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.
- macOS 10.4+
Among the NSXML family of classes—that is, the Foundation classes with the prefix “NSXML” (excluding
NSXMLNode class is the base class. Inheriting from it are the classes
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.
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
Methods to Override
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.
NSXMLNode implements the
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
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.