GSXMLNode 0.2 15 September, 2000 GSXMLNode GSXML.h

XML Node.

nodeWithNamespace: ns name: name prefix: 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.

... 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"]; ...
initWithNamespace: ns name: name prefix: prefix

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

nodeFrom: data

Creation of a new Node from libxml data.

initFrom: data

Creation of a new Node from libxml data.

lib

Return pointer to xmlNode structure.

name

Return Node name.

content

Return Node content.

ns

Return Node namespace.

nsDef

Return namespace definitions of this node.

properties

Return pointer to the first attribute on this node.

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

Return attritubes and values as a dictionary.

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]); }
type

Return type of Node.

doc

Return owner of this node.

children

Return children of this node.

- (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

Return parent of this node.

next

Return next node.

prev

Return previous node.

makeChild: ns name: name content: 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.

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: content

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

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: content

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

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: name value: value

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

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