GSXMLNode $Revision$ $Date$ GSXMLNode GSXML.h

XML Node.

descriptionFromType: type

Return the string constant value for the node type given.

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

XML_ELEMENT_NODE XML_ATTRIBUTE_NODE XML_TEXT_NODE XML_CDATA_SECTION_NODE XML_ENTITY_REF_NODE XML_ENTITY_NODE XML_PI_NODE XML_COMMENT_NODE XML_DOCUMENT_NODE XML_DOCUMENT_TYPE_NODE XML_DOCUMENT_FRAG_NODE XML_NOTATION_NODE XML_HTML_DOCUMENT_NODE XML_DTD_NODE XML_ELEMENT_DECL XML_ATTRIBUTE_DECL XML_ENTITY_DECL XML_NAMESPACE_DECL XML_XINCLUDE_START XML_XINCLUDE_END XML_SGML_DOCUMENT_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 attributes 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]); }
propertiesAsDictionaryWithKeyTransformationSel: 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

Return type of Node.

typeDescription

Return the name of the type of the 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"];
type

Return the numeric type code for this node.

typeDescription

Return the string type code for this node.