< DOMParent > Protocol Reference

Inheritance diagram for < DOMParent >:

< DOMDocument > < DOMDocumentFragment > < DOMElement > DOMParent DOMDocument DOMDocumentFragment DOMElement DOMDocument DOMDocumentFragment DOMElement List of all members.

Detailed Description

Common interface for nodes that can contain other nodes.


Public Member Functions

(NSArray *)  children
(id< DOMNode >)  firstChild
(id< DOMNode >)  lastChild
(BOOL)  containsChild:
(id< DOMNode >)  appendChild:
(void)  appendChildren:
(id< DOMNode >)  insertChild:after:
(id< DOMNode >)  insertChild:before:
(id< DOMNode >)  removeChild:
(void)  removeAllChildren
(id< DOMNode >)  replaceChild:withNode:
(id< DOMElement >)  childElementById:
(NSArray *)  childElementsByName:
(NSArray *)  childElementsByName:inNamespace:

Member Function Documentation

- (id <DOMNode>) appendChild: (id< DOMNode >)  child  
 

Adds a node as a child to this element.

The node is detached before it is added which means that if it was a child of another element or document, it will be removed from that element or document and added as a child to this. If the node is already a child of this parent it will also be detached and inserted last.

These are the rules on which nodes can contain which:

  • DOMDocument cannot contain text, CDATA or attribute nodes.

  • DOMDocument can only contain one doctype node, and only one element node, if a new is appended the previous will be removed.

  • No parent node can contain DOMDocument nodes nor attribute nodes (elements contain attributes separately from other nodes)

There are also rules on which order nodes can be contained in a document:

  • The doctype cannot come after the root element

Moreover, it is not valid to add a node to itself, nor to add a the node parent to a node, for obvious reasons.

Exceptions:
NSInvalidArgumentException Raised if the node is nil
DOMHierarchyRequestException Raised if a node of the wrong type is added to this node, or if the node that is added is the same node that's being added to, or an ancestor of that node.
Parameters:
child The node to add
Returns:
The appended node

- (void) appendChildren: (NSArray *)  children  
 

Adds all children in an array.

Calls appendChild: repeatedly, which is not the most efficient way to do it, but it'll do for now.

Exceptions:
X See appendChild: more info.

- (id <DOMElement>) childElementById: (NSString *)  ID  
 

If there is a child of this document that has the specified ID, that element is returned, otherwise nil.

Since this framework has no idea of what actually is an ID attribute, and what isn't, this method is not correct. What it does it that it finds a child node that has an attribute that returns yes from DOMAttribute::isId. The implementation of that method just assumes that any attribute named "id" (higher or lowercase, or mixed) is an id-attribute.

- (NSArray *) childElementsByName: (NSString *)  name  
 

Searches the subtree at this node for any elements with a specified name (local name) and returns these.

If name is "*", returns all elements.

- (NSArray *) childElementsByName: (NSString *)  name
inNamespace: (NSString *)  namespaceURI
 
 

Searches the subtree at this node for any elements with a specified name (local name) in a specified namespace and returns these.

If name is "*", returns all elements.

- (NSArray *) children  
 

Returns an array of all children. The array is not live, i.e. it does not update it's contents when new nodes are added or removed.

The returned array may be empty.

- (BOOL) containsChild: (id< DOMNode >)  child  
 

Returns YES if this parent contains child. Equality is checked by isEqual:, not #isEqualToNode:.

- (id <DOMNode>) firstChild  
 

Returns the first child of this node, or nil if this node has no children.

- (id <DOMNode>) insertChild: (id< DOMNode >)  child
after: (id< DOMNode >)  node
 
 

Inserts a new node after the specified node.

The new node is detached before it's added, which means that if it's already a child of this node, this will still work

Exceptions:
X See appendChild: more info.
Returns:
The inserted node

- (id <DOMNode>) insertChild: (id< DOMNode >)  child
before: (id< DOMNode >)  other
 
 

Inserts a new node after the specified node.

The new node is detached before it's added, which means that if it's already a child of this node, this will still work.

Exceptions:
X See appendChild: more info.
Returns:
The inserted node

- (id <DOMNode>) lastChild  
 

Returns the last child of this node, or nil if this node has no children.

- (void) removeAllChildren  
 

Removes all children from this parent.

Calls removeChild: repeatedly.

- (id <DOMNode>) removeChild: (id< DOMNode >)  child  
 

Removes the specified node from the list of children.

Returns:
The removed node or nil if no node was removed

- (id <DOMNode>) replaceChild: (id< DOMNode >)  child
withNode: (id< DOMNode >)  other
 
 

Replaces a child with another node.

The replaced child is detached and released.

Exceptions:
X See appendChild: more info.
Returns:
The replaced node