libs-base/Documentation/gsdoc/GSXMLNode.html

430 lines
12 KiB
HTML
Raw Normal View History

<html><head>
<title>GSXMLNode</title>
</head>
<body>
<a href="GSXMLNamespace.html">[Previous]</a>
<a href="GSXML.html">[Up]</a>
<a href="GSXMLAttribute.html">[Next]</a>
<h1>GSXMLNode</h1>
<h3>Authors</h3>
<dl>
<dt>Michael Pakhantsov
<dd>
<dt>Richard Frith-Macdonald
<dd>
</dl>
<p>Version: 0.2</p>
<p>Date: 15 September, 2000</p>
<h2><a name="cont-0">GSXMLNode</a></h2>
<h2><a name="GSXMLNode">GSXMLNode</a></h2>
<p><b>Declared in:</b> GSXML.h</p>
<p><b>Inherits from:</b> <A HREF="NSObject.html#NSObject">NSObject</A></p>
<hr>
<p>
XML Node.
</p>
<h2>Instance Variables</h2>
<ul>
</ul>
<h2>Methods</h2>
<ul>
<li><a href="GSXMLNode.html#method-3">+nodeFrom:</a>
<li><a href="GSXMLNode.html#method-0">+nodeWithNamespace:name:prefix:</a>
<li><a href="GSXMLNode.html#method-17">-children</a>
<li><a href="GSXMLNode.html#method-7">-content</a>
<li><a href="GSXMLNode.html#method-16">-doc</a>
<li><a href="GSXMLNode.html#method-4">-initFrom:</a>
<li><a href="GSXMLNode.html#method-2">-initWithNamespace:name:prefix:</a>
<li><a href="GSXMLNode.html#method-5">-lib</a>
<li><a href="GSXMLNode.html#method-22">-makeChild:name:content:</a>
<li><a href="GSXMLNode.html#method-24">-makeComment:</a>
<li><a href="GSXMLNode.html#method-26">-makePI:</a>
<li><a href="GSXMLNode.html#method-6">-name</a>
<li><a href="GSXMLNode.html#method-20">-next</a>
<li><a href="GSXMLNode.html#method-8">-ns</a>
<li><a href="GSXMLNode.html#method-9">-nsDef</a>
<li><a href="GSXMLNode.html#method-19">-parent</a>
<li><a href="GSXMLNode.html#method-21">-prev</a>
<li><a href="GSXMLNode.html#method-10">-properties</a>
<li><a href="GSXMLNode.html#method-12">-propertiesAsDictionary</a>
<li><a href="GSXMLNode.html#method-28">-setProp:value:</a>
<li><a href="GSXMLNode.html#method-14">-type</a>
<li><a href="GSXMLNode.html#method-15">-typeDescription</a>
</ul>
<hr><h2>Class Methods</h2>
<h3><a name="method-0">nodeWithNamespace:name:prefix:</a></h3>
+ (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>nodeWithNamespace:</b> (<A HREF="GSXMLNamespace.html#GSXMLNamespace">GSXMLNamespace</A>*)ns <b>name:</b> (<A HREF="NSString.html#NSString">NSString</A>*)name <b>prefix:</b> (<A HREF="NSString.html#NSString">NSString</A>*)prefix;<br>
<p>
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.
</p>
<a name="label-1">example</a>
<pre>
...
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"];
...
</pre>
<hr>
<h3><a name="method-3">nodeFrom:</a></h3>
+ (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>nodeFrom:</b> (void*)data;<br>
<p>
Creation of a new Node from libxml data.
</p>
<hr>
<hr><h2>Instances Methods</h2>
<h3><a name="method-2">initWithNamespace:name:prefix:</a></h3>
- (id) <b>initWithNamespace:</b> (<A HREF="GSXMLNamespace.html#GSXMLNamespace">GSXMLNamespace</A>*)ns <b>name:</b> (<A HREF="NSString.html#NSString">NSString</A>*)name <b>prefix:</b> (<A HREF="NSString.html#NSString">NSString</A>*)prefix;<br>
<p>
Creation of a new node elemen, ns is optional (nil).
</p>
<hr>
<h3><a name="method-4">initFrom:</a></h3>
<b>This is the designated initialiser</b><br>
- (id) <b>initFrom:</b> (void*)data;<br>
<p>
Creation of a new Node from libxml data.
</p>
<hr>
<h3><a name="method-5">lib</a></h3>
- (void*) <b>lib</b>;<br>
<p>
Return pointer to xmlNode structure.
</p>
<hr>
<h3><a name="method-6">name</a></h3>
- (<A HREF="NSString.html#NSString">NSString</A>*) <b>name</b>;<br>
<p>
Return Node name.
</p>
<hr>
<h3><a name="method-7">content</a></h3>
- (<A HREF="NSString.html#NSString">NSString</A>*) <b>content</b>;<br>
<p>
Return Node content.
</p>
<hr>
<h3><a name="method-8">ns</a></h3>
- (<A HREF="GSXMLNamespace.html#GSXMLNamespace">GSXMLNamespace</A>*) <b>ns</b>;<br>
<p>
Return Node namespace.
</p>
<hr>
<h3><a name="method-9">nsDef</a></h3>
- (<A HREF="GSXMLNamespace.html#GSXMLNamespace">GSXMLNamespace</A>*) <b>nsDef</b>;<br>
<p>
Return namespace definitions of this node.
</p>
<hr>
<h3><a name="method-10">properties</a></h3>
- (<A HREF="GSXMLAttribute.html#GSXMLAttribute">GSXMLAttribute</A>*) <b>properties</b>;<br>
<p>
Return pointer to the first attribute on this node.
</p>
<a name="label-11">example</a>
<pre>
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]);
}
</pre>
<hr>
<h3><a name="method-12">propertiesAsDictionary</a></h3>
- (<A HREF="NSDictionary.html#NSDictionary">NSDictionary</A>*) <b>propertiesAsDictionary</b>;<br>
<p>
Return attritubes and values as a dictionary.
</p>
<a name="label-13">example</a>
<pre>
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]);
}
</pre>
<hr>
<h3><a name="method-14">type</a></h3>
- (GSXMLNodeType) <b>type</b>;<br>
<p>
Return type of Node.
</p>
<hr>
<h3><a name="method-15">typeDescription</a></h3>
- (<A HREF="NSString.html#NSString">NSString</A>*) <b>typeDescription</b>;<br>
<p>
Return the name of the type of the Node.
</p>
<hr>
<h3><a name="method-16">doc</a></h3>
- (<A HREF="GSXMLDocument.html#GSXMLDocument">GSXMLDocument</A>*) <b>doc</b>;<br>
<p>
Return owner of this node.
</p>
<hr>
<h3><a name="method-17">children</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>children</b>;<br>
<p>
Return children of this node.
</p>
<a name="label-18">example</a>
<pre>
- (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;
}
</pre>
<hr>
<h3><a name="method-19">parent</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>parent</b>;<br>
<p>
Return parent of this node.
</p>
<hr>
<h3><a name="method-20">next</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>next</b>;<br>
<p>
Return next node.
</p>
<hr>
<h3><a name="method-21">prev</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>prev</b>;<br>
<p>
Return previous node.
</p>
<hr>
<h3><a name="method-22">makeChild:name:content:</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>makeChild:</b> (<A HREF="GSXMLNamespace.html#GSXMLNamespace">GSXMLNamespace</A>*)ns <b>name:</b> (<A HREF="NSString.html#NSString">NSString</A>*)name <b>content:</b> (<A HREF="NSString.html#NSString">NSString</A>*)content;<br>
<p>
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.
</p>
<a name="label-23">example</a>
<pre>
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];
</pre>
<hr>
<h3><a name="method-24">makeComment:</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>makeComment:</b> (<A HREF="NSString.html#NSString">NSString</A>*)content;<br>
<p>
Creation of a new comment element, added at the end of
parent children list.
</p>
<a name="label-25">example</a>
<pre>
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 "];
</pre>
<hr>
<h3><a name="method-26">makePI:</a></h3>
- (<A HREF="GSXMLNode.html#GSXMLNode">GSXMLNode</A>*) <b>makePI:</b> (<A HREF="NSString.html#NSString">NSString</A>*)content;<br>
<p>
Creation of a new process instruction element,
added at the end of parent children list.
</p>
<a name="label-27">example</a>
<pre>
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"];
</pre>
<hr>
<h3><a name="method-28">setProp:value:</a></h3>
- (<A HREF="GSXMLAttribute.html#GSXMLAttribute">GSXMLAttribute</A>*) <b>setProp:</b> (<A HREF="NSString.html#NSString">NSString</A>*)name <b>value:</b> (<A HREF="NSString.html#NSString">NSString</A>*)value;<br>
<p>
Set (or reset) an attribute carried by a node.
</p>
<a name="label-29">example</a>
<pre>
id n1 = [GSXMLNode nodeWithNamespace: nil name: nodeName];
[n1 setProp: @"prop1" value: @"value1"];
[n1 setProp: @"prop2" value: @"value2"];
[n1 setProp: @"prop3" value: @"value3"];
</pre>
<hr>
</body>
</html>