< DOMNode > Protocol Reference

Inheritance diagram for < DOMNode >:

< DOMAttribute > < DOMCharacterData > < DOMDocType > < DOMDocument > < DOMDocumentFragment > < DOMElement > DOMNode < DOMProcessingInstruction > List of all members.

Detailed Description

The DOMNode protocol defines the common interface of all nodes A node can, for example, be an element, a comment or a processing instruction.

One may ask why there is a protocol named DOMNode and a class with the same name. The reason is to increase the extensibility of the framework.

The thought is that when adding new node types, or extensions of existing node types one should not be forced to extend by inheritance (which would be bad design since it couples the extension to tightly to the existing framework).

The DOMNode class is an abstract class for internal use within the framework. A class that extends the framework should conform to the DOMNode protocol not inherit from the DOMNode class.


Public Member Functions

(NSString *)  nodeName
(NSString *)  nodeValue
(DOMNodeType nodeType
(id< DOMParent, DOMNode >)  parentNode
(void)  setParentNode:
(id< DOMDocument >)  ownerDocument
(id< DOMNode >)  detach
(BOOL)  isDetached
(BOOL)  hasChildren
(id< DOMNode >)  previousSibling
(id< DOMNode >)  nextSibling
(NSString *)  textContent
(void)  setTextContent:
(BOOL)  isEqualToNode:

Member Function Documentation

- (id <DOMNode>) detach  
 

Detaches this node from it's parent.

A detached node belongs to no parent and no document, it is free.

When detached, the node removes itself from it's parent's list of children, and removes the reference to it's parent.

A document node or document fragment can't be detached.

Returns:
Returns the node itself.

- (BOOL) hasChildren  
 

Returns YES if this node has child nodes.

- (BOOL) isDetached  
 

Returns whether or not this method is detached.

Returns YES if this node has no parent and NO otherwise.

A document or document fragment is never detached.

Returns:
YES if detached, NO otherwise

- (BOOL) isEqualToNode: (id< DOMNode >)  node  
 

Checks for equality, as defined by being of the same node type and having the same properties.

The implementation of this method depends heavily on which type of node it is, it can be very expensive when the node is a parent since it checks for equality recursively. See NSArray's isEqualToArray: for more information.

When comparing text nodes, CDATA sections and comments, ignorable whitespace is ignored. Ignoreable whitespace is, in this framework, defined as the characters in the set returned by NSCharacterSet's whitespaceAndNewlineCharacterSet.

- (id <DOMNode>) nextSibling  
 

Returns the node after this node in the node's parent's list of children, or nil if this node is the last

- (NSString *) nodeName  
 

Returns the name of this node.

The name and value of a node varies accordning to the table below:

 Node type      name                    value
 ------------------------------------------------------------
 Attribute        name of attribute       value
 CDATASection     "#cdata-section"        content
 Comment          "#comment"              content
 Document         "#document"             nil
 DocumentFragment "#document-fragment"    nil
 DocumentType     document type name      nil
 Element          element name            nil
 PI               target                  content, w/o target
 Text             "#text"                 content

- (DOMNodeType) nodeType  
 

Deprecated:
This mechanism for determining node type is now deprecated, since it doesn't work well with polymorphism (when checking for text nodes you would have to check for both text nodes and cdata-sections, and when checking for parent nodes you would have to check for both element nodes and document nodes).

- (NSString *) nodeValue  
 

Returns the value of this node.

The name and value of a node varies accordning to the type, see the table in the documentation of nodeName: for more information.

- (id <DOMDocument>) ownerDocument  
 

Returns the document this node is placed in or nil, if the node is not part of a document.

A node is considered part of a document if it's parent is part of that document, or the node is the document element of a document.

- (id <DOMParent, DOMNode>) parentNode  
 

Returns the parent of this node or nil, if the node has no parent.

- (id <DOMNode>) previousSibling  
 

Returns the node before this node in the node's parent's list of children, or nil if this node is the first.

- (void) setParentNode: (id< DOMParent, DOMNode >)  newParent  
 

Sets the parent of this node.

It's your responsibility to make sure that the node is added to the new parent, it is not done automatically.

Please note that in order to prevent retain-cycles the node does NOT retain the parent.

- (void) setTextContent: (NSString *)  text  
 

Sets the text contained by this node.

The result of this method depends on the node type, see table below:

 Node type            setTextContent
 ------------------------------------------------------------
 Attribute            same as -setValue
 CDATASection         same as -setData
 Comment              same as -setData
 Text                 same as -setData
 PI                   same as -setDataString
 DocumentFragment     all children are removed and replaced by
     & Elemenet           a single text node
 DocumentType         no effect
 Document             no effect

- (NSString *) textContent  
 

Returns the text contained by this node.

The result of this method depends on the node type, see table below:

 Node type            textContent
 ------------------------------------------------------------
 Attribute            same as -nodeValue
 CDATASection         same as -nodeValue
 Comment              same as -nodeValue
 Text                 same as -nodeValue
 PI                   same as -nodeValue
 DocumentFragment     concatenation of textContent of all 
     & Element            children, excluding comments and pi's
 DocumentType         nil
 Document             nil