XML::Sablotron::DOM - The DOM interface to Sablotron's internal structures use XML::Sablotron::DOM; my $situa = new XML::Sablotron::Situation(); my $doc = new XML::Sablotron::DOM::Document(SITUATION => $sit); my $e = $doc->createElement($situa, "foo"); my $t = $doc->createTextNode($situa, "this is my text"); print $doc->toString(); Sablotron uses internally the DOM-like data structures to represent parsed XML trees. In the `sdom.h' header file is defined a subset of functions allowing the DOM access to these structures.

What is it good for
You may find this module useful if you need to

Situation
There is one significant extension to the DOM specification. Since Sablotron os designed to support multithreading processing (and well reentrant code too), you need create and use special context for error processing. This context is called the situation. A instance of this object MUST be passed as the first parameter to almost all calls in the `XML::Sablotron::DOM' code. Some easy-to-use default behavior may be introduced in later releases. See `perldoc XML::Sablotron' for more details. Perl objects representing nodes of the DOM tree live independently on internal structures of Sablotron. If you create and populate the document, its structure is not related to the lifecycle of your Perl variables. It is good for you, but there are two exceptions to this: As results from above, you have to force XML::Sablotron::DOM to free document, if you want. Use $doc->freeDocument($sit); to to it. Another way is to use the autodispode feature (see the documentation for the method autodispose and document constructor). If you will try to access the node, which was previously disposed by Sablotron (perhaps with the all tree), your Perl code will die with exception -1. Use `eval {};' to avoid program termination. The `XML::Sablotron::DOM' defines several packages. Just will be created manually in your code; they are mostly returned as a return values from many functions. The `XML::Sablotron::DOM' package is almost empty, and serves as a parent module for the other packages. By default this module exports no symbols into the callers package. If want to use some predefined constants or functions, you may use use XML::Sablotron::DOM qw( :constants :functions );

constants
Constants are defined for: `ELEMENT_NODE, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, DOCUMENT_FRAGMENT_NODE, NOTATION_NODE, OTHER_NODE' `SDOM_OK, INDEX_SIZE_ERR, HIERARCHY_ERR, WRONG_DOCUMENT_ERR, NO_MODIFICATION_ALLOWED_ERR, NOT_FOUND_ERR, INVALID_NODE_TYPE_ERR, QUERY_PARSE_ERR, QUERY_EXECUTION_ERR, NOT_OK'

parse
This function parses the document specified by the URI. There is currently no support for scheme handler for this operation (see the XML::Sablotron manpage) but it will be added soon. Function returns the XML::Sablotron::DOM::Document object instance. XML::Sablotron::DOM::parse($sit, $uri); The situation to be used. The URI of the document to be parsed.

parseBuffer
This function parses the literal data specified. XML::Sablotron::DOM::parseBuffer($sit, $data); The situation to be used. The string containing the XML data to be parsed.

parseStylesheet
This function parses the stylesheet specified by the URI. There is currently no support for scheme handler for this operation (see the XML::Sablotron manpage) but it will be added soon. Function returns the XML::Sablotron::DOM::Document object instance. XML::Sablotron::DOM::parseStylesheet($sit, $uri); The situation to be used. The URI of the stylesheet to be parsed.

parseStylesheetBuffer
This function parses the stylesheet given by the literal data. XML::Sablotron::DOM::parseStylesheetBuffer($sit, $data); The situation to be used. The string containing the stylesheet to be parsed. This packages is used to represent the Sablotron internal representation of the node. It is the common ancestor of all other types.

equals
Check if the to perl representations of the node represent the same node in the DOM document. Synopsis: $node1->equals($node2); The node to be compared to.

getNodeType
Returns the node type. See the section on "XML::Sablotron::DOM" for more details. $node->getNodeType([$situa]); The situation to be used (optional).

getNodeName
For ELEMENT_NODE and ATTRIBUTE_NODE returns the name of the node. For other node types return as follows: TEXT_NODE => "#text", CDATA_SECTION_NODE => #cdata-section, COMMENT_NODE => "#comment", DOCUMNET_NODE => "#document" Synopsis: $node->getNodeName([$situa]); The situation to be used (optional).

setNodeName
Sets the name of the node. Exceptions: for TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE and DOCUMENT_NODE Synopsis: $node->setNodeName($name [, $situa]); The new node name. The situation to be used (optional).

getNodeValue
returns the content of TEXT_NODE, CDATA_SECTION_NODE and COMMENT_NODE, otherwise returns undef. Synopsis: $node->getNodeValue([$situa]); The situation to be used (optional).

setNodeValue
Sets the content of the node for TEXT_NODE, CDATA_SECTION_NODE and COMMENT_NODE. Exceptions: for ELEMENT_NODE, DOCUMENT_NODE Synopsis: $node->setNodeValue($value [, $situa]); The new node value. The situation to be used (optional).

getParentNode
Returns the parent node, if there is any. Otherwise returns undef. Undefined value is always returned for the DOCUMENT_NODE. Synopsis: $node->getNodeValue([$situa]); The situation to be used (optional).

getFirstChild
Get the first child of the node or undef. Synopsis: $node->getFirstChild([$situa]); The situation to be used (optional).

getLastChild
Get the last child of the node or undef. Synopsis: $node->getLastChild([$situa]); The situation to be used (optional).

getPreviousSibling
Returns the node immediately preceding the node. Returns undef, if there is no such node. Synopsis: $node->getPreviousSibling([$situa]); The situation to be used (optional).

getNextSibling
Returns the node immediately following the node. Returns undef, if there is no such node. Synopsis: $node->getNextSibling([$situa]); The situation to be used (optional).

getChildNodes
Returns the reference to the array of all child nodes of given node. Synopsis: $node->getChildNodes([$situa]); The situation to be used (optional).

getOwnerDocument
Returns the document owning the node. It is always the document, which created this node. For document itself the return value is undef. Synopsis: $node->getOwnerDocument([$situa]); The situation to be used (optional).

insertBefore
Makes a new node the child of the node. It is put right before the reference node. If the reference node is not defined, the new node is appended to the child list. Exceptions: Raised if the node doesn't allow children of given type. Raised if the new node is not owned by the same document as the node. Synopsis: $node->insertBefore($new_node, $ref_node [, $situa]); The inserted node. The reference node. The new node is to be inserted right before this node. May be undef; in this case the new node is appended. The situation to be used (optional).

appendChild
Appends the new node to the list of children of the node. Exceptions: Raised if the node doesn't allow children of given type. Raised if the new node is not owned by the same document as the node. Synopsis: $node->appendChild($child, [$situa]); The node to be appended. The situation to be used (optional).

removeChild
Remove the child node from the list of children of the node. Exceptions: Raised if the removed node is not the child of the node. Synopsis: $node->removeChild($child, [, $situa]); The node to be removed. The situation to be used (optional).

replaceChild
Replace the child node with the new one. Exceptions: Raised if the node doesn't allow children of given type. Raised if the new node is not owned by the same document as the node. Raised if the replaced node is not the child of the node. Synopsis: $node->replaceChild($child, $old_child [, $situa]); The new child to be inserted (in the place of the $old_child) The node to be replaced. The situation to be used (optional).

xql
Executes the XPath expression and returns the ARRAYREF of resulting nodes. Synopsis: $node->xql($expr [, $situa]); The expression to be replaced. The situation to be used (optional). Represents the whole DOM document (the "/" root element).

new
Create the new empty document. Synopsis: $doc = XML::Sablotron::DOM::Document->new([AUTODISPOSE => $ad]); Specifies if the document is to be deleted after the last Perl reference is dropped,

autodispose
Reads or set the autodispose flag, This flag causes, that the document is destroyed after the last Perl reference is undefined. Synopsis: $doc->autodispose([$ad]); Specifies if the document is to be deleted after the last Perl reference is dropped,

freeDocument
Disposes all memory allocated by Sablotron for the DOM document. This is the only way how to do it. See the section on "MEMORY ISSUES" for more details. Synopsis: $doc->freeDocument([$situa]); The situation to be used (optional).

toString
Serializes the document tree into the string representation. Synopsis: $doc->toString([$situa]) The situation to be used (optional).

cloneNode
Clone the node. The children of the node may be cloned too. The cloned node may be from another document; cloned nodes are always owned by the calling document. Parent of the cloned node is not set. Synopsis: $doc->cloneNode($node, $deep [, $situa]); The node to be cloned. If true, all children of the node are cloned too. The situation to be used (optional).

createElement
Creates the new ELEMENT_NODE. The parent of the node is not set; the owner document is set to the document. Synopsis: $doc->createElement($name [, $situa]); The new element name. The situation to be used (optional).

createTextNode
Creates the new TEXT_NODE. The parent of the node is not set; the owner document is set to the document. Synopsis: $doc->createTextNode($data [, $situa]); The initial value of the node. The situation to be used (optional).

createCDATASection
Creates the new CDATA_SECTION_NODE. The parent of the node is not set; the owner document is set to the document. Synopsis: $doc->createCDATASection($data [, $situa]); The initial value of the node. The situation to be used (optional).

createComment
Creates the new COMMENT_NODE. The parent of the node is not set; the owner document is set to the document. Synopsis: $doc->createComment($data [, $situa]); The initial value of the node. The situation to be used (optional).

createProcessingInstruction
Creates the new PROCESSING_INSTRUCTION_NODE. The parent of the node is not set; the owner document is set to the document. Synopsis: $doc->createProcessingInstruction($target, $data [, $situa]); The target for the pi. The data for the pi. The situation to be used (optional). Represents the element of the tree.

getAttribute
$hashref = $e->getAttribute($name [, $situa]); The name of queried attribute. The situation to be used (optional).

setAttribute
$hashref = $e->setAttribute($name, $value [, $situa]); The name of attribute to be set. The value of the new attribute. The situation to be used (optional).

getAttributes
$hashref = $e->getAttributes([$situa]); The situation to be used (optional).

setAttributes
$hashref = $e->setAttributes($hashref [, $situa]); The HASHREF value. Referenced hash contains name/value pair to be used. The situation to be used (optional).

removeAttribute
$hashref = $e->removeAttribute($name [, $situa]); The name of attribute to be removed. The situation to be used (optional).

toString
Serializes the element and its subtree into the string representation. Synopsis: $e->toString([$situa]) The situation to be used (optional). Pavel Hlavnicka, pavel@gingerall.cz; Ginger Alliance LLC; perl(1).