[Previous] [Up] [Next]

GSXMLNode

Authors

Michael Pakhantsov
Richard Frith-Macdonald

Version: $Revision$

Date: $Date$

GSXMLNode

GSXMLNode

Declared in: GSXML.h

Inherits from: NSObject


XML Node.

Instance Variables

Methods


Class Methods

descriptionFromType:

+ (NSString*) descriptionFromType: (int)type;

Return the string constant value for the node type given.


typeFromDescription:

+ (int) typeFromDescription: (NSString*)desc;

Return the numeric constant value for the node type named. This method is inefficient, so the returned value should be saved for re-use later. The possible values are -


nodeWithNamespace:name:prefix:

+ (GSXMLNode*) nodeWithNamespace: (GSXMLNamespace*)ns name: (NSString*)name prefix: (NSString*)prefix;

Creation of a new Node. This function will refuse to create a Node with a similar prefix than an existing one present on this node.

example


             ...
             GSXMLNamespace *ns1;
             GSXMLNode *node1, *node2;
             NSString *prefix = @"mac-os-property";
             NSString *href   = @"http://www.gnustep.org/some/location";

             ns = [GSXMLNamespace namespaceWithNode: nil
                                               href: href
                                             prefix: prefix];
             node1 = [GSXMLNode nodeWithNamespace: ns name: @"node1"];
             node2 = [GSXMLNode nodeWithNamespace: nil name: @"node2"];
             ...

          
 

nodeFrom:

+ (GSXMLNode*) nodeFrom: (void*)data;

Creation of a new Node from libxml data.



Instances Methods

initWithNamespace:name:prefix:

- (id) initWithNamespace: (GSXMLNamespace*)ns name: (NSString*)name prefix: (NSString*)prefix;

Creation of a new node elemen, ns is optional (nil).


initFrom:

This is the designated initialiser
- (id) initFrom: (void*)data;

Creation of a new Node from libxml data.


lib

- (void*) lib;

Return pointer to xmlNode structure.


name

- (NSString*) name;

Return Node name.


content

- (NSString*) content;

Return Node content.


ns

- (GSXMLNamespace*) ns;

Return Node namespace.


nsDef

- (GSXMLNamespace*) nsDef;

Return namespace definitions of this node.


properties

- (GSXMLAttribute*) properties;

Return pointer to the first attribute on this node.

example


            GSXMLNode *n1;
            GSXMLAttribute *a;

            n1 = [GSXMLNode nodeWithNamespace: nil name: nodeName];
            [n1 setProp: @"prop1" value: @"value1"];
            [n1 setProp: @"prop2" value: @"value2"];
            [n1 setProp: @"prop3" value: @"value3"];

            a = [n1 properties];
            NSLog(@"n1 property name - %@ value - %@", [a name], [a value]);
            while ((a = [a next]) != nil)
              {
                NSLog(@"n1 property name - %@ value - %@", [a name], [a value]);
              }

           
 

propertiesAsDictionary

- (NSMutableDictionary*) propertiesAsDictionary;

Return attributes and values as a dictionary.

example


            GSXMLNode *n1;
            NSMutableDictionary *prop;
            NSEnumerator *e;
            id key;

            prop = [n1 propertiesAsDictionary];
            e = [prop keyEnumerator];
            while ((key = [e nextObject]) != nil)
              {
                NSLog(@"property name - %@ value - %@", key,
		  [prop objectForKey: key]);
              }
	    
 

propertiesAsDictionaryWithKeyTransformationSel:

- (NSMutableDictionary*) propertiesAsDictionaryWithKeyTransformationSel: (SEL)keyTransformSel;

Return attributes and values as a dictionary, but applies the specified selector to each key before adding the key and value to the dictionary. The selector must be a method of NSString taking no arguments and returning an object suitable for use as a dictionary key.

This method exists for the use of GSWeb ... it is probably not of much use elsewhere.


type

- (GSXMLNodeType) type;

Return type of Node.


typeDescription

- (NSString*) typeDescription;

Return the name of the type of the Node.


doc

- (GSXMLDocument*) doc;

Return owner of this node.


children

- (GSXMLNode*) children;

Return children of this node.

example

              - (GSXMLNode*) nextElement: (GSXMLNode*)node
              {
                while (node != nil)
                  {
                    if ([node type] == XML_ELEMENT_NODE)
                      {
                        return node;
                      }
                    if ([node children] != nil)
                      {
                        node = [self nextElement: [node children]];
                      }
		    else
		      node = [node next];
                  }
                return node;
              }
           
 

parent

- (GSXMLNode*) parent;

Return parent of this node.


next

- (GSXMLNode*) next;

Return next node.


prev

- (GSXMLNode*) prev;

Return previous node.


makeChild:name:content:

- (GSXMLNode*) makeChild: (GSXMLNamespace*)ns name: (NSString*)name content: (NSString*)content;

Creation of a new child element, added at the end of parent children list. ns and content parameters are optional (may be nil). If content is non nil, a child list containing the TEXTs and ENTITY_REFs node will be created. Return previous node.

example


  GSXMLNode *n1, *n2;
  GSXMLDocument *d, *d1;

  d = [GSXMLDocument documentWithVersion: @"1.0"];
  [d setRoot: [d makeNodeWithNamespace: nil
				  name: @"plist"
			       content: nil]];
  [[d root] setProp: @"version" value: @"0.9"];
  n1 = [[d root] makeChildWithNamespace: nil
				   name: @"dict"
				content: nil];
  [n1 makeChildWithNamespace: nil name: @"key" content: @"Year Of Birth"];
  [n1 makeChildWithNamespace: nil name: @"integer" content: @"65"];
  [n1 makeChildWithNamespace: nil name: @"key" content: @"Pets Names"];
  [n1 makeChildWithNamespace: nil name: @"array" content: nil];

	    
 

makeComment:

- (GSXMLNode*) makeComment: (NSString*)content;

Creation of a new comment element, added at the end of parent children list.

example

  d = [GSXMLDocument documentWithVersion: @"1.0"];

  [d setRoot: [d makeNodeWithNamespace: nil name: @"plist" content: nil]];
  [[d root] setProp: @"version" value: @"0.9"];
  n1 = [[d root] makeChildWithNamespace: nil name: @"dict" content: nil];
  [n1 makeComment: @" this is a comment "];
	    
 

makePI:

- (GSXMLNode*) makePI: (NSString*)content;

Creation of a new process instruction element, added at the end of parent children list.

example

  d = [GSXMLDocument documentWithVersion: @"1.0"];

  [d setRoot: [d makeNodeWithNamespace: nil name: @"plist" content: nil]];
  [[d root] setProp: @"version" value: @"0.9"];
  n1 = [[d root] makeChildWithNamespace: nil name: @"dict" content: nil];
  [n1 makeComment: @" this is a comment "];
  [n1 makePI: @"pi1" content: @"this is a process instruction"];
	    
 

setProp:value:

- (GSXMLAttribute*) setProp: (NSString*)name value: (NSString*)value;

Set (or reset) an attribute carried by a node.

example

  id n1 = [GSXMLNode nodeWithNamespace: nil name: nodeName];
  [n1 setProp: @"prop1" value: @"value1"];
  [n1 setProp: @"prop2" value: @"value2"];
  [n1 setProp: @"prop3" value: @"value3"];

	    
 

type

- (int) type;

Return the numeric type code for this node.


typeDescription

- (NSString*) typeDescription;

Return the string type code for this node.