mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 18:21:04 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9698 72102866-910b-0410-8b05-ffd578937521
522 lines
13 KiB
HTML
522 lines
13 KiB
HTML
<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: $Revision$</p>
|
|
<p>Date: $Date$</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> NSObject</p>
|
|
<hr>
|
|
|
|
<p>
|
|
|
|
XML Node.
|
|
</p>
|
|
|
|
|
|
<h2>Instance Variables </h2>
|
|
<ul>
|
|
</ul>
|
|
<h2>Methods </h2>
|
|
<ul>
|
|
<li ><a href ="GSXMLNode.html#method-0">+descriptionFromType:</a>
|
|
<li ><a href ="GSXMLNode.html#method-5">+nodeFrom:</a>
|
|
<li ><a href ="GSXMLNode.html#method-2">+nodeWithNamespace:name:prefix:</a>
|
|
<li ><a href ="GSXMLNode.html#method-1">+typeFromDescription:</a>
|
|
<li ><a href ="GSXMLNode.html#method-20">-children</a>
|
|
<li ><a href ="GSXMLNode.html#method-9">-content</a>
|
|
<li ><a href ="GSXMLNode.html#method-19">-doc</a>
|
|
<li ><a href ="GSXMLNode.html#method-6">-initFrom:</a>
|
|
<li ><a href ="GSXMLNode.html#method-4">-initWithNamespace:name:prefix:</a>
|
|
<li ><a href ="GSXMLNode.html#method-7">-lib</a>
|
|
<li ><a href ="GSXMLNode.html#method-25">-makeChild:name:content:</a>
|
|
<li ><a href ="GSXMLNode.html#method-27">-makeComment:</a>
|
|
<li ><a href ="GSXMLNode.html#method-29">-makePI:</a>
|
|
<li ><a href ="GSXMLNode.html#method-8">-name</a>
|
|
<li ><a href ="GSXMLNode.html#method-23">-next</a>
|
|
<li ><a href ="GSXMLNode.html#method-10">-ns</a>
|
|
<li ><a href ="GSXMLNode.html#method-11">-nsDef</a>
|
|
<li ><a href ="GSXMLNode.html#method-22">-parent</a>
|
|
<li ><a href ="GSXMLNode.html#method-24">-prev</a>
|
|
<li ><a href ="GSXMLNode.html#method-12">-properties</a>
|
|
<li ><a href ="GSXMLNode.html#method-14">-propertiesAsDictionary</a>
|
|
<li ><a href ="GSXMLNode.html#method-16">-propertiesAsDictionaryWithKeyTransformationSel:</a>
|
|
<li ><a href ="GSXMLNode.html#method-31">-setProp:value:</a>
|
|
<li ><a href ="GSXMLNode.html#method-33">-type</a>
|
|
<li ><a href ="GSXMLNode.html#method-17">-type</a>
|
|
<li ><a href ="GSXMLNode.html#method-18">-typeDescription</a>
|
|
<li ><a href ="GSXMLNode.html#method-34">-typeDescription</a>
|
|
</ul>
|
|
<hr><h2>Class Methods </h2>
|
|
<h3><a name ="method-0">descriptionFromType:</a></h3>
|
|
+ (NSString*) <b>descriptionFromType:</b> (int)type;<br>
|
|
|
|
<p>
|
|
|
|
Return the string constant value for the node
|
|
type given.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-1">typeFromDescription:</a></h3>
|
|
+ (int) <b>typeFromDescription:</b> (NSString*)desc;<br>
|
|
|
|
<p>
|
|
|
|
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 -
|
|
</p>
|
|
|
|
<ul>
|
|
<li >XML_ELEMENT_NODE
|
|
<li >XML_ATTRIBUTE_NODE
|
|
<li >XML_TEXT_NODE
|
|
<li >XML_CDATA_SECTION_NODE
|
|
<li >XML_ENTITY_REF_NODE
|
|
<li >XML_ENTITY_NODE
|
|
<li >XML_PI_NODE
|
|
<li >XML_COMMENT_NODE
|
|
<li >XML_DOCUMENT_NODE
|
|
<li >XML_DOCUMENT_TYPE_NODE
|
|
<li >XML_DOCUMENT_FRAG_NODE
|
|
<li >XML_NOTATION_NODE
|
|
<li >XML_HTML_DOCUMENT_NODE
|
|
<li >XML_DTD_NODE
|
|
<li >XML_ELEMENT_DECL
|
|
<li >XML_ATTRIBUTE_DECL
|
|
<li >XML_ENTITY_DECL
|
|
<li >XML_NAMESPACE_DECL
|
|
<li >XML_XINCLUDE_START
|
|
<li >XML_XINCLUDE_END
|
|
<li >XML_SGML_DOCUMENT_NODE
|
|
</ul>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-2">nodeWithNamespace:name:prefix:</a></h3>
|
|
+ (GSXMLNode*) <b>nodeWithNamespace:</b> (GSXMLNamespace*)ns <b>name:</b> (NSString*)name <b>prefix:</b> (NSString*)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-3">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-5">nodeFrom:</a></h3>
|
|
+ (GSXMLNode*) <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-4">initWithNamespace:name:prefix:</a></h3>
|
|
- (id) <b>initWithNamespace:</b> (GSXMLNamespace*)ns <b>name:</b> (NSString*)name <b>prefix:</b> (NSString*)prefix;<br>
|
|
|
|
<p>
|
|
|
|
Creation of a new node elemen, ns is optional (nil).
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-6">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-7">lib</a></h3>
|
|
- (void*) <b>lib</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return pointer to xmlNode structure.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-8">name</a></h3>
|
|
- (NSString*) <b>name</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return Node name.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-9">content</a></h3>
|
|
- (NSString*) <b>content</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return Node content.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-10">ns</a></h3>
|
|
- (GSXMLNamespace*) <b>ns</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return Node namespace.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-11">nsDef</a></h3>
|
|
- (GSXMLNamespace*) <b>nsDef</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return namespace definitions of this node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-12">properties</a></h3>
|
|
- (GSXMLAttribute*) <b>properties</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return pointer to the first attribute on this node.
|
|
</p>
|
|
|
|
<a name ="label-13">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-14">propertiesAsDictionary</a></h3>
|
|
- (NSMutableDictionary*) <b>propertiesAsDictionary</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return attributes and values as a dictionary.
|
|
</p>
|
|
|
|
<a name ="label-15">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-16">propertiesAsDictionaryWithKeyTransformationSel:</a></h3>
|
|
- (NSMutableDictionary*) <b>propertiesAsDictionaryWithKeyTransformationSel:</b> (SEL)keyTransformSel;<br>
|
|
|
|
<p>
|
|
|
|
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.
|
|
</p>
|
|
|
|
<p>
|
|
|
|
This method exists for the use of GSWeb ... it is probably
|
|
not of much use elsewhere.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-17">type</a></h3>
|
|
- (GSXMLNodeType) <b>type</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return type of Node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-18">typeDescription</a></h3>
|
|
- (NSString*) <b>typeDescription</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return the name of the type of the Node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-19">doc</a></h3>
|
|
- (GSXMLDocument*) <b>doc</b>;<br>
|
|
|
|
<p>
|
|
Return owner of this node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-20">children</a></h3>
|
|
- (GSXMLNode*) <b>children</b>;<br>
|
|
|
|
<p>
|
|
Return children of this node.
|
|
</p>
|
|
|
|
<a name ="label-21">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-22">parent</a></h3>
|
|
- (GSXMLNode*) <b>parent</b>;<br>
|
|
|
|
<p>
|
|
Return parent of this node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-23">next</a></h3>
|
|
- (GSXMLNode*) <b>next</b>;<br>
|
|
|
|
<p>
|
|
Return next node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-24">prev</a></h3>
|
|
- (GSXMLNode*) <b>prev</b>;<br>
|
|
|
|
<p>
|
|
Return previous node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-25">makeChild:name:content:</a></h3>
|
|
- (GSXMLNode*) <b>makeChild:</b> (GSXMLNamespace*)ns <b>name:</b> (NSString*)name <b>content:</b> (NSString*)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-26">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-27">makeComment:</a></h3>
|
|
- (GSXMLNode*) <b>makeComment:</b> (NSString*)content;<br>
|
|
|
|
<p>
|
|
|
|
Creation of a new comment element, added at the end of
|
|
parent children list.
|
|
</p>
|
|
|
|
<a name ="label-28">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-29">makePI:</a></h3>
|
|
- (GSXMLNode*) <b>makePI:</b> (NSString*)content;<br>
|
|
|
|
<p>
|
|
|
|
Creation of a new process instruction element,
|
|
added at the end of parent children list.
|
|
</p>
|
|
|
|
<a name ="label-30">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-31">setProp:value:</a></h3>
|
|
- (GSXMLAttribute*) <b>setProp:</b> (NSString*)name <b>value:</b> (NSString*)value;<br>
|
|
|
|
<p>
|
|
Set (or reset) an attribute carried by a node.
|
|
</p>
|
|
|
|
<a name ="label-32">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>
|
|
<h3><a name ="method-33">type</a></h3>
|
|
- (int) <b>type</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return the numeric type code for this node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-34">typeDescription</a></h3>
|
|
- (NSString*) <b>typeDescription</b>;<br>
|
|
|
|
<p>
|
|
|
|
Return the string type code for this node.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
</body>
|
|
|
|
</html>
|