NSXMLNode Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.4 and later. |
| Companion guide | |
| Declared in | NSXMLNode.h NSXMLNodeOptions.h |
Overview
Objects of the NSXMLNode class are nodes in the abstract, logical tree structure that represents an XML document. Node objects can be of different kinds, corresponding to the following markup constructs in an XML document: element, attribute, text, processing instruction, namespace, and comment. In addition, a document-node object (specifically, an instance of NSXMLDocument) represents an XML document in its entirety. NSXMLNode objects can also represent document type declarations as well as declarations in Document Type Definitions (DTDs). Class factory methods of NSXMLNode enable you to create nodes of each kind. Only document, element, and DTD nodes may have child nodes.
Among the NSXML family of classes—that is, the Foundation classes with the prefix “NSXML” (excluding NSXMLParser)—the NSXMLNode class is the base class. Inheriting from it are the classes NSXMLElement, NSXMLDocument, NSXMLDTD, and NSXMLDTDNode. NSXMLNode specifies the interface common to all XML node objects and defines common node behavior and attributes, for example hierarchy level, node name and value, tree traversal, and the ability to emit representative XML markup text.
Subclassing Notes
You can subclass NSXMLNode if you want nodes of kinds different from the supported ones, You can also create a subclass with more specialized attributes or behavior than NSXMLNode.
Methods to Override
To subclass NSXMLNode you need to override the primary initializer, initWithKind:options:, and the methods listed below. In most cases, you need only invoke the superclass implementation, adding any subclass-specific code before or after the invocation, as necessary.
By default NSXMLNode implements the NSObject isEqual: method to perform a deep comparison: two NSXMLNode objects are not considered equal unless they have the same name, same child nodes, same attributes, and so on. The comparison looks at the node and its children, but does not include the node’s parent. If you want a different standard of comparison, override isEqual:.
Special Considerations
Because of the architecture and data model of NSXML, when it parses and processes a source of XML it cannot know about your subclass unless you override the NSXMLDocument class method replacementClassForClass: to return your custom class in place of an NSXML class. If your custom class has no direct NSXML counterpart—for example, it is a subclass of NSXMLNode that represents CDATA sections—then you can walk the tree after it has been created and insert the new node where appropriate.
Adopted Protocols
Tasks
Creating and Initializing Node Objects
-
– initWithKind: -
– initWithKind:options: -
+ document -
+ documentWithRootElement: -
+ elementWithName: -
+ elementWithName:children:attributes: -
+ elementWithName:stringValue: -
+ elementWithName:URI: -
+ attributeWithName:stringValue: -
+ attributeWithName:URI:stringValue: -
+ textWithStringValue: -
+ commentWithStringValue: -
+ namespaceWithName:stringValue: -
+ DTDNodeWithXMLString: -
+ predefinedNamespaceForPrefix: -
+ processingInstructionWithName:stringValue:
Managing XML Node Objects
-
– index -
– kind -
– level -
– setName: -
– name -
– setObjectValue: -
– objectValue -
– setStringValue: -
– setStringValue:resolvingEntities: -
– stringValue -
– setURI: -
– URI
Navigating the Tree of Nodes
-
– rootDocument -
– parent -
– childAtIndex: -
– childCount -
– children -
– nextNode -
– nextSibling -
– previousNode -
– previousSibling -
– detach
Emitting Node Content
Executing Queries
Managing Namespaces
Class Methods
attributeWithName:stringValue:
Returns an NSXMLNode object representing an attribute node with a given name and string.
Parameters
- name
A string that is the name of an attribute.
- value
A string that is the value of an attribute.
Return Value
An NSXMLNode object of kind NSXMLAttributeKind or nil if the object couldn't be created.
Discussion
For example, in the attribute “id=`12345’”, “id” is the attribute name and “12345” is the attribute value.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hattributeWithName:URI:stringValue:
Returns an NSXMLNode object representing an attribute node with a given qualified name and string.
Parameters
- name
A string that is the name of an attribute.
- URI
A URI (Universal Resource Identifier) that qualifies name.
- value
A string that is the value of the attribute.
Return Value
An NSXMLNode object of kind NSXMLAttributeKind or nil if the object couldn't be created.
Discussion
For example, in the attribute “bst:id=`12345’”, “bst” is the name qualifier (derived from the URI), “id” is the attribute name, and “12345” is the attribute value.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hcommentWithStringValue:
Returns an NSXMLNode object representing an comment node containing given text.
Parameters
- stringValue
A string specifying the text of the comment. You may specify
nilor an empty string (see Return Value).
Return Value
An NSXMLNode object representing an comment node (NSXMLCommentKind) containing the text stringValue or nil if the object couldn't be created. If stringValue is nil or an empty string, a content-less comment node is returned (<!--->).
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hdocument
Returns an empty document node.
Return Value
An empty document node—that is, an NSXMLDocument instance without a root element or XML-declaration information (version, encoding, standalone flag). Returns nil if the object couldn't be created.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hdocumentWithRootElement:
Returns an NSXMLDocument object initialized with a given root element.
Parameters
- element
An
NSXMLElementobject representing an element.
Return Value
An NSXMLDocument object initialized with the root element element or nil if the object couldn't be created.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hDTDNodeWithXMLString:
Returns a NSXMLDTDNode object representing the DTD declaration for an element, attribute, entity, or notation based on a given string.
Parameters
- string
A string that is a DTD declaration. The receiver parses this string to determine the kind of DTD node to create.
Return Value
An NSXMLDTDNode object representing the DTD declaration or nil if the object couldn't be created.
Discussion
For example, if string is the following:
<!ENTITY name (#PCDATA)> |
NSXMLNode is able to assign the created node object a kind of NSXMLEntityDeclarationKind by parsing “ENTITY”.
Note that if an attribute-list declaration (<!ATTLIST...> )has multiple attributes NSXMLNode only creates an NSXMLDTDNode object for the last attribute in the declaration.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.helementWithName:
Returns an NSXMLElement object with a given tag identifier, or name
Parameters
- name
A string that is the name (or tag identifier) of an element.
Return Value
An NSXMLElement object or nil if the object couldn't be created.
Discussion
The equivalent XML markup is <name></name>.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.helementWithName:children:attributes:
Returns an NSXMLElement object with the given tag (name), attributes, and children.
Parameters
- name
A string that is the name (tag identifier) of the element.
- children
An array of
NSXMLElementobjects orNSXMLNodeobjects of kindsNSXMLElementKind,NSXMLProcessingInstructionKind,NSXMLCommentKind, andNSXMLTextKind. Specifynilif there are no children to add to this node object.- attributes
An array of
NSXMLNodeobjects of kindNSXMLAttributeKind. Specifynilif there are no attributes to add to this node object.
Return Value
An NSXMLElement object or nil if the object couldn't be created.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.helementWithName:stringValue:
Returns an NSXMLElement object with a single text-node child containing the specified text.
Parameters
- name
A string that is the name (tag identifier) of the element.
- string
A string that is the content of the receiver's text node.
Return Value
An NSXMLElement object with a single text-node child—an NSXMLNode object of kind NSXMLTextKind—containing the text specified in string. Returns nil if the object couldn't be created.
Discussion
The equivalent XML markup is <name>string</name>.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.helementWithName:URI:
Returns an element whose fully qualified name is specified.
Parameters
- name
A string that is the name (or tag identifier) of an element.
- URI
A URI (Universal Resource Identifier) that qualifies name.
Return Value
An NSXMLElement object or nil if the object cannot be created.
Discussion
The equivalent XML markup is <URI:name></URI:name>.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hlocalNameForName:
Returns the local name from the specified qualified name.
Parameters
- qName
A string that is a qualified name.
Discussion
For example, if the qualified name is “bst:title”, this method returns “title”.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hnamespaceWithName:stringValue:
Returns an NSXMLNode object representing a namespace with a specified name and URI.
Parameters
- name
A string that is the name of the namespace. Specify an empty string for name to get the default namespace.
- value
A string that identifies the URI associated with the namespace.
Return Value
An NSXMLNode object of kind NSXMLNamespaceKind or nil if the object couldn't be created.
Discussion
The equivalent namespace declaration in XML markup is xmlns:name="value".
Special Considerations
Applications linked on OS X v10.6 or later will throw an exception if the name parameter is nil.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hpredefinedNamespaceForPrefix:
Returns an NSXMLNode object representing one of the predefined namespaces with the specified prefix.
Parameters
- name
A string specifying a prefix for a predefined namespace, for example “xml”, “xs”, or “xsi”.
Return Value
An NSXMLNode object of kind NSXMLNamespaceKind or nil if the object couldn't be created. If something other than a predefined-namespace prefix is specified, the method returns nil.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hprefixForName:
Returns the prefix from the specified qualified name.
Parameters
- qName
A string that is a qualified name.
Discussion
For example, if the qualified name is “bst:title”, this method returns “bst”.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hprocessingInstructionWithName:stringValue:
Returns an NSXMLNode object representing a processing instruction with a specified name and value.
Parameters
- name
A string that is the name of the processing instruction.
- value
A string that is the value of the processing instruction.
Return Value
An NSXMLNode object of kind NSXMLProcessingInstructionKind or nil if the object couldn't be created.
Discussion
The equivalent XML markup is <?name value?>.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.htextWithStringValue:
Returns an NSXMLNode object representing a text node with specified content.
Parameters
- value
A string that is the textual content of the node.
Return Value
An NSXMLNode object of kind NSXMLTextKind initialized with the textual value or nil if the object couldn't be created.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hInstance Methods
canonicalXMLStringPreservingComments:
Returns a string object encapsulating the receiver’s XML in canonical form.
Parameters
- comments
YESto preserve comments,NOotherwise.
Discussion
Be sure to set the input option NSXMLNodePreserveWhitespace for true canonical form. The canonical form of an XML document is defined by the World Wide Web Consortium at http://www.w3.org/TR/xml-c14n. Generally, if two documents with varying physical representations have the same canonical form, then they are considered logically equivalent within the given application context. The following list summarizes most key aspects of canonical form as defined by the W3C recommendation:
Encodes the document in UTF-8.
Normalizes line breaks to “#xA” on input before parsing.
Normalizes attribute values in the manner of a validating processor.
Replaces character and parsed entity references with their character content.
Replaces CDATA sections with their character content.
Removes the XML declaration and the document type declaration (DTD).
Converts empty elements to start-end tag pairs.
Normalizes whitespace outside of the document element and within start and end tags.
Retains all whitespace characters in content (excluding characters removed during line-feed normalization).
Sets attribute value delimiters to quotation marks (double quotes).
Replaces special characters in attribute values and character content with character references.
Removes superfluous namespace declarations from each element.
Adds default attributes to each element.
Imposes lexicographic order on the namespace declarations and attributes of each element.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hchildAtIndex:
Returns the child node of the receiver at the specified location.
Parameters
- index
An integer specifying a node position in the receiver's array of children. If index is out of bounds, an exception is raised.
Return Value
An NSXMLNode object or nil f the receiver has no children.
Discussion
The receiver should be an NSXMLNode object representing a document, element, or document type declaration. The returned node object can represent an element, comment, text, or processing instruction.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hchildCount
Returns the number of child nodes the receiver has.
Discussion
This receiver should be an NSXMLNode object representing a document, element, or document type declaration. For performance reasons, use this method instead of getting the count from the array returned by children (for example, [[thisNode children] count]).
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hchildren
Returns an immutable array containing the child nodes of the receiver (as NSXMLNode objects).
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hdescription
Returns a description of the receiver.
Discussion
Use this method for debugging rather than for generating XML output. It could yield more information than XMLString and XMLStringWithOptions:.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hdetach
Detaches the receiver from its parent node.
Discussion
This method is applicable to NSXMLNode objects representing elements, text, comments, processing instructions, attributes, and namespaces. Once the node object is detached, you can add it as a child node of another parent.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hindex
Returns the index of the receiver identifying its position relative to its sibling nodes.
Return Value
An integer that is the index of the receiver relative to its sibling nodes.
Discussion
The first child node of a parent has an index of zero.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hinitWithKind:
Returns an NSXMLNode instance initialized with the constant indicating node kind.
Parameters
- kind
An
enumconstant of typeNode Kind Constantsthat indicates the type of node. See “Constants” for a list of valid NSXMLNodeKind constants.
Return Value
An NSXMLNode object initialized with kind or nil if the object couldn't be created. If kind is not a valid NSXMLNodeKind constant, the method returns an NSXMLNode object of kind NSXMLInvalidKind.
Discussion
This method invokes initWithKind:options: with the options parameter set to NSXMLNodeOptionsNone.
Do not use this initializer for creating instances of NSXMLDTDNode for attribute-list declarations. Instead, use the DTDNodeWithXMLString: class method of this class or the initWithXMLString: method of the NSXMLDTDNode class.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hinitWithKind:options:
Returns an NSXMLNode instance initialized with the constant indicating node kind and one or more initialization options.
Parameters
- kind
An
enumconstant of typeNode Kind Constantsthat indicates the type of node. See “Constants” for a list of valid NSXMLNodeKind constants.- options
One or more constants that specify initialization options; if there are multiple constants, bit-OR them together. These options request operations on the represented XML related to fidelity (for example, preserving entities), quoting style, handling of empty elements, and other things. See “Constants” for a list of valid node-initialization constants.
Return Value
An NSXMLNode object initialized with the given kind and options, or nil if the object couldn't be created. If kind is not a valid NSXMLNodeKind constant, the method returns an NSXMLNode object of kind NSXMLInvalidKind.
Discussion
Do not use this initializer for creating instances of NSXMLDTDNode for attribute-list declarations. Instead, use the DTDNodeWithXMLString: class method of this class or the initWithXMLString: method of the NSXMLDTDNode class.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hkind
Returns the kind of node the receiver is as a constant of type Node Kind Constants.
Discussion
NSXMLNode objects can represent documents, elements, attributes, namespaces, text, processing instructions, comments, document type declarations, and specific declarations within DTDs. See “Constants” for a list of valid NSXMLNodeKind constants
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hlevel
Returns the nesting level of the receiver within the tree hierarchy.
Return Value
An integer indicating a nesting level.
Discussion
The root element of a document has a nesting level of one.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hlocalName
Returns the local name of the receiver.
Return Value
A string containing the local name of the receiver.
Discussion
The local name is the part of a node name that follows a namespace-qualifying colon or the full name if there is no colon. For example, “chapter” is the local name in the qualified name “acme:chapter”.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hname
Returns the name of the receiver.
Return Value
Returns a string specifying the name of the receiver. May return nil if the receiver is not a valid kind of node (see discussion).
Discussion
This method is applicable only to NSXMLNode objects representing elements, attributes, namespaces, processing instructions, and DTD-declaration nodes. If the receiver is not an object of one of these kinds, this method returns nil. For example, in the following construction:
<title>Chapter One</title> |
The returned name for the element is “title”. If the name is associated with a namespace, the qualified name is returned. For example, if you create an element with local name “foo” and URI “http://bar.com” and the namespace “xmlns:baz=‘http://bar.com’” is applied to this node, when you invoke this method on the node you get “baz:foo”.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hnextNode
Returns the next NSXMLNode object in document order.
Discussion
You use this method to “walk” forward through the tree structure representing an XML document or document section. (Use previousNode to traverse the tree in the opposite direction.) Document order is the natural order that XML constructs appear in markup text. If you send this message to the last node in the tree, nil is returned. NSXMLNode bypasses namespace and attribute nodes when it traverses a tree in document order.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hnextSibling
Returns the next NSXMLNode object that is a sibling node to the receiver.
Discussion
This object will have an index value that is one more than the receiver’s. If there are no more subsequent siblings (that is, other child nodes of the receiver’s parent) the method returns nil.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hnodesForXPath:error:
Returns the nodes resulting from executing an XPath query upon the receiver.
Parameters
- xpath
A string that expresses an XPath query.
- error
If query errors occur, indirectly returns an
NSErrorobject describing the errors.
Return Value
An array of NSXMLNode objects that match the query, or an empty array if there are no matches.
Discussion
The receiver acts as the context item for the query (“.”). If you have explicitly added adjacent text nodes as children of an element, you should invoke the NSXMLElement method normalizeAdjacentTextNodesPreservingCDATA: (with an argument of NO) on the element before applying any XPath queries to it; this method coalesces these text nodes. The same precaution applies if you have processed a document preserving CDATA sections and these sections are adjacent to text nodes.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hobjectsForXQuery:constants:error:
Returns the objects resulting from executing an XQuery query upon the receiver.
Parameters
- xquery
A string that expresses an XQuery query.
- constants
A dictionary containing externally declared constants where the name of each constant variable is a key.
- error
If query errors occur, indirectly returns an
NSErrorobject describing the errors.
Discussion
The receiver acts as the context item for the query (“.”). If the receiver has been changed after parsing to have multiple adjacent text nodes, you should invoke the NSXMLElement method normalizeAdjacentTextNodesPreservingCDATA: (with an argument of NO) to coalesce the text nodes before querying.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hobjectsForXQuery:error:
Returns the objects resulting from executing an XQuery query upon the receiver.
Parameters
- xquery
A string that expresses an XQuery query.
- error
If query errors occur, indirectly returns an
NSErrorobject describing the errors.
Discussion
The receiver acts as the context item for the query (“.”). If the receiver has been changed after parsing to have multiple adjacent text nodes, you should invoke the NSXMLElement method normalizeAdjacentTextNodesPreservingCDATA: (with an argument of NO) to coalesce the text nodes before querying .This convenience method invokes objectsForXQuery:constants:error: with nil for the constants dictionary.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hobjectValue
Returns the object value of the receiver.
Return Value
The object value of the receiver, which may be the same as the value returned by stringValue. For nodes without content (for example, document nodes), this method returns the string value, or an empty string if there is no string value.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hparent
Returns the parent node of the receiver.
Discussion
Document nodes and standalone nodes (that is, the root of a detached branch of a tree) have no parent, and sending this message to them returns nil. A one-to-one relationship does not always exists between a parent and its children; although a namespace or attribute node cannot be a child, it still has a parent element.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hprefix
Returns the prefix of the receiver’s name.
Return Value
A string containing the receiver’s prefix. This method returns an empty string if the receiver’s name is not qualified by a namespace.
Discussion
The prefix is the part of a namespace-qualified name that precedes the colon. For example, “acme” is the prefix in the qualified name “acme:chapter”.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hpreviousNode
Returns the previous NSXMLNode object in document order.
Discussion
You use this method to “walk” backward through the tree structure representing an XML document or document section. (Use nextNode to traverse the tree in the opposite direction.) Document order is the natural order that XML constructs appear in markup text. If you send this message to the first node in the tree (that is, the root element), nil is returned. NSXMLNode bypasses namespace and attribute nodes when it traverses a tree in document order.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hpreviousSibling
Returns the previous NSXMLNode object that is a sibling node to the receiver.
Discussion
This object will have an index value that is one less than the receiver’s. If there are no more previous siblings (that is, other child nodes of the receiver’s parent) the method returns nil
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hrootDocument
Returns the NSXMLDocument object containing the root element and representing the XML document as a whole.
Discussion
If the receiver is a standalone node (that is, a node at the head of a detached branch of the tree), this method returns nil.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hsetName:
Sets the name of the receiver.
Parameters
- name
A string that is the name to assign to the receiver.
Discussion
This method is effective for the following node kinds: element, attribute, namespace, processing-instruction, document type declaration, element declaration, attribute declaration, entity declaration, and notation declaration. If an NSXMLNode object that requires a name doesn’t have one, it cannot be written out as an XML string.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hsetObjectValue:
Sets the content of the receiver to an object value.
Parameters
- value
An object to assign as the value to the receiver.
Discussion
This method can only be invoked on NSXMLNode objects that may have content, specifically elements, attributes, namespaces, processing instructions, text, and DTD-declaration nodes. The given object is usually a Foundation equivalent to one of the atomic types in the XQuery data model: NSNumber (integer, decimal, float, double, Boolean), NSString (string), NSCalendarDate (date), NSData (base64Binary and hexBinary), NSURL (URI), and NSArray (NMTOKENS, IDREFS, ENTITIES). However, you can also set the object value to be a custom value and register a value transformer (that is, an instance of NSValueTransformer) to convert the object value to an XML string representation when the node is asked for its string value.
Setting a node’s object value removes all existing children, including processing instructions and comments. Setting an element node’s object value creates a text node as the sole child. When an NSXMLNode object emits its object-value contents as a string, and it can determine the type of the value, it ensures that it the string is in a canonical form as defined by the W3C XML Schema Data Types specification.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hsetStringValue:
Sets the content of the receiver as a string value.
Parameters
- string
A string to assign as the value of the receiver.
Discussion
This method invokes setStringValue:resolvingEntities:, passing in an argument of NO for the second parameter. This method can only be invoked on NSXMLNode objects that may have content, specifically elements, attributes, namespaces, processing instructions, text, and DTD-declaration nodes. Setting the string value of a node object removes all existing children, including processing instructions and comments. Setting the string value of an element-node object creates a text node as the sole child.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSXMLNode.hsetStringValue:resolvingEntities:
Sets the content of the receiver as a string value and, optionally, resolves character references, predefined entities, and user-defined entities as declared in the associated DTD.
Parameters
- string
A string to assign as the value of the receiver.
- resolve
YESto resolve character references, predefined entities, and user-defined entities as declared in the associated DTD;NOotherwise. Namespace and processing-instruction nodes have their entities resolved even if resolve isNO.
Discussion
User-defined entities not declared in the DTD remain in their unresolved form. This method can only be invoked on NSXMLNode objects that may have content, specifically elements, attributes, namespaces, processing instructions, text, and DTD-declaration nodes. Setting the string value of a node object removes all existing children, including processing instructions and comments. Setting the string value of an element -node object creates a text node as the sole child.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hsetURI:
Sets the URI of the receiver.
Parameters
- URI
The URI to associate with the receiver. A URI (Universal Resource Identifier) is a scheme such as “http” or “ftp” followed by a colon character, and then a scheme-specific part.
Discussion
The receiver must be an NSXMLElement or NSXMLDocument document, or an attribute (that is, anNSXMLNode object of type NSXMLAttributeKind). For documents it is the URI of document origin.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hstringValue
Returns the content of the receiver as a string value.
Discussion
If the receiver is a node object of element kind, the content is that of any text-node children. This method recursively visits elements nodes and concatenates their text nodes in document order with no intervening spaces. If the receiver’s content is set as an object value, this method returns the string value representing the object. If the object value is one of the standard, built-in ones (NSNumber, NSCalendarDate, and so on), the string value is in canonical format as defined by the W3C XML Schema Data Types specification. If the object value is not represented by one of these classes (or if the default value transformer for a class has been overridden), the string value is generated by the NSValueTransformer registered for that object type.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hURI
Returns the URI associated with the receiver.
Discussion
A node’s URI is derived from its namespace or a document’s URI; for documents, the URI comes either from the parsed XML or is explicitly set. You cannot change the URI for a particular node other for than a namespace or document node.
Availability
- Available in OS X v10.4 and later.
See Also
-
setURI:(NSXMLDocument)
Declared In
NSXMLNode.hXMLString
Returns the string representation of the receiver as it would appear in an XML document.
Discussion
The returned string includes the string representations of all children. This method invokes XMLStringWithOptions: with an options argument of NSXMLNodeOptionsNone.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hXMLStringWithOptions:
Returns the string representation of the receiver as it would appear in an XML document, with one or more output options specified.
Parameters
- options
One or more
enumconstants identifying an output option; bit-OR multiple constants together. See “Constants” for a list of valid constants for specifying output options.
Discussion
The returned string includes the string representations of all children.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hXPath
Returns the XPath expression identifying the receiver’s location in the document tree.
Discussion
For example, this method might return a string such as “foo/bar[2]/baz”. The result of this method can be used directly in the nodesForXPath:error: and objectsForXQuery:constants:error: methods.
Availability
- Available in OS X v10.4 and later.
Declared In
NSXMLNode.hConstants
Node Kind Constants
NSXMLNode declares the following constants of type NSXMLNodeKind for specifying a node’s kind in the initializer methods initWithKind: and initWithKind:options::
enum {
NSXMLInvalidKind = 0,
NSXMLDocumentKind,
NSXMLElementKind,
NSXMLAttributeKind,
NSXMLNamespaceKind,
NSXMLProcessingInstructionKind,
NSXMLCommentKind,
NSXMLTextKind,
NSXMLDTDKind,
NSXMLEntityDeclarationKind,
NSXMLAttributeDeclarationKind,
NSXMLElementDeclarationKind,
NSXMLNotationDeclarationKind
};
typedef NSUInteger NSXMLNodeKind;
Constants
NSXMLInvalidKindIndicates a node object created without a valid kind being specified (as returned by the
kindmethod).Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLDocumentKindSpecifies a document node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLElementKindSpecifies an element node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLAttributeKindSpecifies an attribute node
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLNamespaceKindSpecifies a namespace node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLProcessingInstructionKindSpecifies a processing-instruction node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLCommentKindSpecifies a comment node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLTextKindSpecifies a text node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLDTDKindSpecifies a document-type declaration (DTD) node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLEntityDeclarationKindSpecifies an entity-declaration node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLAttributeDeclarationKindSpecifies an attribute-list declaration node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLElementDeclarationKindSpecifies an element declaration node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.NSXMLNotationDeclarationKindSpecifies a notation declaration node.
Available in OS X v10.4 and later.
Declared in
NSXMLNode.h.
Input and Output Options
These constants are input and output options for all NSXMLNode objects (unless otherwise indicated), including NSXMLDocument objects. You can specify these options (OR’ing multiple options) in the NSXMLNode methods initWithKind:options: and XMLStringWithOptions:.
enum {
NSXMLNodeOptionsNone = 0,
NSXMLNodeIsCDATA = 1 << 0,
NSXMLNodeExpandEmptyElement = 1 << 1, // <a></a>
NSXMLNodeCompactEmptyElement = 1 << 2, // <a/>
NSXMLNodeUseSingleQuotes = 1 << 3,
NSXMLNodeUseDoubleQuotes = 1 << 4,
NSXMLDocumentTidyHTML = 1 << 9,
NSXMLDocumentTidyXML = 1 << 10,
NSXMLDocumentValidate = 1 << 13,
NSXMLNodeLoadExternalEntitiesAlways = 1UL << 14,
NSXMLNodeLoadExternalEntitiesSameOriginOnly = 1UL << 15,
NSXMLNodeLoadExternalEntitiesNever = 1UL << 19,
NSXMLDocumentXInclude = 1 << 16,
NSXMLNodePrettyPrint = 1 << 17,
NSXMLDocumentIncludeContentTypeDeclaration = 1 << 18,
NSXMLNodePreserveNamespaceOrder = 1 << 20,
NSXMLNodePreserveAttributeOrder = 1 << 21,
NSXMLNodePreserveEntities = 1 << 22,
NSXMLNodePreservePrefixes = 1 << 23,
NSXMLNodePreserveCDATA = 1 << 24,
NSXMLNodePreserveWhitespace = 1 << 25,
NSXMLNodePreserveDTD = 1 << 26,
NSXMLNodePreserveCharacterReferences = 1 << 27,
NSXMLNodePreserveEmptyElements =
(NSXMLNodeExpandEmptyElement | NSXMLNodeCompactEmptyElement),
NSXMLNodePreserveQuotes =
(NSXMLNodeUseSingleQuotes | NSXMLNodeUseDoubleQuotes),
NSXMLNodePreserveAll = (
NSXMLNodePreserveNamespaceOrder |
NSXMLNodePreserveAttributeOrder |
NSXMLNodePreserveEntities |
NSXMLNodePreservePrefixes |
NSXMLNodePreserveCDATA |
NSXMLNodePreserveEmptyElements |
NSXMLNodePreserveQuotes |
NSXMLNodePreserveWhitespace |
NSXMLNodePreserveDTD |
NSXMLNodePreserveCharacterReferences |
0xFFF00000) // high 12 bits
};
Constants
NSXMLNodeOptionsNoneNo options are requested for this input or output action.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeIsCDATASpecifies that a text node contains and is written out as a CDATA section.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeExpandEmptyElementRequests that an element should be expanded when empty; for example,
<flag></flag>. This is the default.Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeCompactEmptyElementRequests that an element should be contracted when empty; for example,
<flag/>.Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeUseSingleQuotesRequests that NSXML use single quotes for the value of an attribute or namespace node.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeUseDoubleQuotesRequests that NSXML use double quotes for the value of an attribute or namespace node. This is the default.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeLoadExternalEntitiesAlwaysRequests that external entities are always loaded.
Requests that external entities are always loaded. You may choose only one of
NSXMLNodeLoadExternalEntitiesAlways,NSXMLNodeLoadExternalEntitiesSameOriginOnly, orNSXMLNodeLoadExternalEntitiesNeveror none.Choosing none results in the system-default behavior. For applications linked on OS X v10.6 and earlier, this is
NSXMLNodeLoadExternalEntitiesAlways. For applications linked on OS X v10.7 or later, all entities that don't require network access are loaded.If an external entity fails to load, the document is invalid and the parse is aborted with an error.
Available in OS X v10.7 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeLoadExternalEntitiesSameOriginOnlyRequests that external entities are always loaded and only applies when a URL has been provided.
It loads entities with target URLs that match the host, scheme, and port of the document URL.You may choose only one of
NSXMLNodeLoadExternalEntitiesAlways,NSXMLNodeLoadExternalEntitiesSameOriginOnly, orNSXMLNodeLoadExternalEntitiesNeveror none.Choosing none results in the system-default behavior. For applications linked on OS X v10.6 and earlier, this is
NSXMLNodeLoadExternalEntitiesAlways. For applications linked on OS X v10.7 or later, all entities that don't require network access are loaded.If an external entity fails to load, the document is invalid and the parse is aborted with an error.
Available in OS X v10.7 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodeLoadExternalEntitiesNeverRequests that external entities are never loaded.
You may choose only one of
NSXMLNodeLoadExternalEntitiesAlways,NSXMLNodeLoadExternalEntitiesSameOriginOnly, orNSXMLNodeLoadExternalEntitiesNeveror none.Requests that external entities are never loaded. You may choose only one of
NSXMLNodeLoadExternalEntitiesAlways,NSXMLNodeLoadExternalEntitiesSameOriginOnly, orNSXMLNodeLoadExternalEntitiesNeveror none.Choosing none results in the system-default behavior. For applications linked on OS X v10.6 and earlier, this is
NSXMLNodeLoadExternalEntitiesAlways. For applications linked on OS X v10.7 or later, all entities that don't require network access are loaded.Available in OS X v10.7 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePrettyPrintPrint this node with extra space for readability. (Output)
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveNamespaceOrderRequests NSXML to preserve the order of namespace URI definitions as in the source XML.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveAttributeOrderRequests that NSXMLNode preserve the order of attributes as in the source XML.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveEntitiesSpecifies that entities (
&xyz;) should not be resolved for XML output of this node.Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveCharacterReferencesSpecifies that character references (
&#nnn;) should not be resolved for XML output of this node.Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreservePrefixesRequests NSXMLNode not to choose prefixes based on the closest namespace URI definition.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveCDATARequests that NSXMLNode preserve CDATA blocks where defined in the input XML.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveWhitespaceRequests NSXMLNode to preserve whitespace characters (such as tabs and carriage returns) in the XML source that are not part of node content.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveEmptyElementsSpecifies that empty elements in the input XML be preserved in their contracted or expanded form.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveQuotesSpecifies that the quoting style used in the input XML (single or double quotes) be preserved.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveDTDSpecifies that declarations in a DTD should be preserved until it the DTD is modified. For example, parameter entities are by default expanded; with this option, they are written out as they originally occur in the DTD.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.NSXMLNodePreserveAllTurns on all preservation options: attribute and namespace order, entities, prefixes, CDATA, whitespace, quotes, and empty elements. You should try to turn on preservation options selectively because turning on all preservation options significantly affects performance.
Available in OS X v10.4 and later.
Declared in
NSXMLNodeOptions.h.
Discussion
The options with “Preserve” in their names are applicable only when external sources of XML are parsed; they have no effect on node objects that are programmatically created. Other options are used in initialization and output methods of NSXMLDocument; see the NSXMLDocument reference documentation for details.
© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-06-06)