Class jabberwerx.NodeBuilder (MINIMAL)
Utility class to build DOMs programmatically. This class is used to create most of the XMPP data.
Constructor Attributes | Constructor Name and Description |
---|---|
jabberwerx.NodeBuilder(data)
Creates a new jabberwerx.NodeBuilder The value of {data} may be an Element or a String. |
Field Attributes | Field Name and Description |
---|---|
The current data
|
|
The document (used for creating nodes)
|
|
The parent node builder
|
Method Attributes | Method Name and Description |
---|---|
attribute(name, val)
Adds or updates an attribute to this NodeBuilder's data.
|
|
element(name, attrs)
Appends a new element to this NodeBuilder's data, with the given
name and attributes.
|
|
node(n)
Appends the given node to this NodeBuilder's data:
|
|
text(val)
Appends a new text node to this NodeBuilder's data.
|
|
xml(val)
Appends the given value as parsed XML to this NodeBuilder's data. |
Class Detail
jabberwerx.NodeBuilder(data)
Creates a new jabberwerx.NodeBuilder
The value of {data} may be an Element or a String. If it is a string, it is expected to be an expanded name in one of the following forms:
- {namespace-uri}prefix:local-name
- {namespace-uri}local-name
- prefix:local-name
- local-name
- Parameters:
- {Element|String} data Optional
- The context element, or the expanded-name of the root element.
- Throws:
- {TypeError}
- If {data} is defined, not an element, not a Document, or not a valid expanded name
Field Detail
{Element}
data
The current data
{Document}
document
The document (used for creating nodes)
{jabberwerx.NodeBuilder}
parent
The parent node builder
Method Detail
{jabberwerx.NodeBuilder}
attribute(name, val)
Adds or updates an attribute to this NodeBuilder's data.
NOTE: namespaced attributes are not supported
- Parameters:
- {String} name
- The name of the attribute
- {String} val
- The attribute value
- Throws:
- {TypeError}
- if {name} is not valid
- Returns:
- {jabberwerx.NodeBuilder} This builder
{jabberwerx.NodeBuilder}
element(name, attrs)
Appends a new element to this NodeBuilder's data, with the given
name and attributes. The created element is automatically appended
to this NodeBuilder's data.
If expanded-name uses form 2 (local-name, no namespace), then the namespace for the parent is used.
- Parameters:
- {String} name
- The expanded name of the new element
- {Object} attrs Optional
- A hashtable of attribute names to attribute values
- Throws:
- {TypeError}
- if {name} is not a valid expanded name
- Returns:
- {jabberwerx.NodeBuilder} The builder for the new element, with the current builder as its parent.
{jabberwerx.NodeBuilder}
node(n)
Appends the given node to this NodeBuilder's data:
- If {n} is a document, its documentElement is appended to this NodeBuilder's data and a NodeBuilder wrapping that element is returned
- If {n} is an element, it is cloned and appended to this NodeBuilder's data and a NodeBuilder wrapping the cloned element is returned
- If {n} is a TextNode, its value is appended to this NodeBuilder's data and this NodeBuilder is returned
- Otherwise, a TypeError is thrown
- Parameters:
- {Node} n
- The node to append
- Throws:
- {TypeError}
- If {node} is invalid
- Returns:
- {jabberwerx.NodeBuilder} The builder appropriate for {node}
{jabberwerx.NodeBuilder}
text(val)
Appends a new text node to this NodeBuilder's data.
- Parameters:
- {String} val
- The text node value
- Returns:
- {jabberwerx.NodeBuilder} this builder
{jabberwerx.NodeBuilder}
xml(val)
Appends the given value as parsed XML to this NodeBuilder's data.
- Parameters:
- {String} val
- The XML to parse and append
- Returns:
- {jabberwerx.NodeBuilder} This NodeBuilder