| 1 |
<?xml version="1.0" standalone="yes"?> |
| 2 |
<html><head><title>XML::LibXML::Document - DOM Document Class</title><link rev="made" href="mailto:[email protected]"/></head><body><ul><li><a href="#NAME">NAME</a></li><li><a href="#SYNOPSIS">SYNOPSIS</a></li><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#Methods">Methods</a></li></ul></li><li><a href="#SEE_ALSO">SEE ALSO</a></li><li><a href="#VERSION">VERSION</a></li></ul><hr/><p/><h1><a name="NAME">NAME</a></h1><p> |
| 3 |
XML::LibXML::Document - DOM Document Class |
| 4 |
|
| 5 |
</p><p/><hr/><h1><a name="SYNOPSIS">SYNOPSIS</a></h1><p/><pre> use XML::LibXML::Document; |
| 6 |
</pre><p/><pre> $dom = XML::LibXML::Document->new( $version, $encoding ); |
| 7 |
$dom = XML::LibXML::Document->createDocument( $version, $encoding ); |
| 8 |
$strEncoding = $doc->getEncoding(); |
| 9 |
$strVersion = $doc->getVersion(); |
| 10 |
$docstring = $dom->toString([$format]); |
| 11 |
$bool = $dom->is_valid(); |
| 12 |
$root = $dom->getDocumentElement($name, $namespace ); |
| 13 |
$dom->setDocumentElement( $root ); |
| 14 |
$element = $dom->createElement( $nodename ); |
| 15 |
$element = $dom->createElementNS( $namespaceURI, $qname ); |
| 16 |
$text = $dom->createTextNode( $content_text ); |
| 17 |
$comment = $dom->createComment( $comment_text ); |
| 18 |
$attrnode = $doc->createAttribute($name [,$value]); |
| 19 |
$attrnode = $doc->createAttributeNS( namespaceURI, $name [,$value] ); |
| 20 |
$cdata = $dom->create( $cdata_content ); |
| 21 |
$document->importNode( $node [, $move] ); |
| 22 |
</pre><p/><hr/><h1><a name="DESCRIPTION">DESCRIPTION</a></h1><p> |
| 23 |
The Document Class is the result of a parsing process. But sometimes it is |
| 24 |
necessary to create a Document from scratch. The DOM Document Class |
| 25 |
provides functions that are conform to the DOM Core naming style. It |
| 26 |
inherits all functions from <em>XML::LibXML::Node</em> as specified in DOM Level2. This enables to access the nodes beside the |
| 27 |
root element on document level - a <em>DTD</em> for example. The support for these nodes is limited at the moment, so I |
| 28 |
would recommend, not to use <em>node</em> functions on <em>documents</em>. It is suggested that one should always create a node not bound to any |
| 29 |
document. There is no need of really including the node to the document, |
| 30 |
but once the node is bound to a document, it is quite safe that all strings |
| 31 |
have the correct encoding. If an unbound textnode with an iso encoded |
| 32 |
string is created (e.g. with $CLASS->new()), the <em>toString</em> function may not return the expected result. This seems like a limitation |
| 33 |
as long UTF8 encoding is assured. If iso encoded strings come into play it |
| 34 |
is much safer to use the node creation functions of <strong>XML::LibXML::Document</strong>. |
| 35 |
|
| 36 |
</p><p/><hr/><h2><a name="Methods">Methods</a></h2><dl><dt><strong><a name="item_new">new</a></strong></dt><dd><p> |
| 37 |
alias for <code>createDocument()</code></p></dd><dt><strong><a name="item_createDocument">createDocument</a></strong></dt><dd><p> |
| 38 |
The constructor for the document class. As Parameter it takes the version |
| 39 |
string and (optionally) the ecoding string. Simply calling <strong>createDocument</strong> will create the document: |
| 40 |
|
| 41 |
</p><p/><pre> |
| 42 |
<?xml version="your version" encoding="your encoding"?> |
| 43 |
</pre><p> |
| 44 |
Both parameter are optional. The default value for <strong>$version</strong> is <em>1.0</em> , of course. If the <strong>$encoding</strong> parameter is not set, the encoding will be left unset, which means UTF8 is |
| 45 |
implied (and set). The call of <strong>createDocument</strong> without any parameter will result the following code: |
| 46 |
|
| 47 |
</p><p/><pre> |
| 48 |
<?xml version="1.0"?> |
| 49 |
</pre></dd><dt><strong><a name="item_getEncoding">getEncoding</a></strong></dt><dd><p> |
| 50 |
returns the encoding string of the document |
| 51 |
|
| 52 |
</p></dd><dt><strong><a name="item_getVersion">getVersion</a></strong></dt><dd><p> |
| 53 |
returns the version string of the document |
| 54 |
|
| 55 |
</p></dd><dt><strong><a name="item_toString">toString</a></strong></dt><dd><p><strong>toString</strong> is a deparsing function, so the DOM Tree can be translated into a string, |
| 56 |
ready for output. The optional <strong>$format</strong> parameter sets the indenting of the output. This parameter is expected to |
| 57 |
be an <em>integer</em> value, that specifies the number of linebreaks for each node. For more |
| 58 |
information about the formatted output check the documentation of <em>xmlDocDumpFormatMemory</em> in <em>libxml2/tree.h</em> . |
| 59 |
|
| 60 |
</p></dd><dt><strong><a name="item_is_valid">is_valid</a></strong></dt><dd><p> |
| 61 |
Returns either TRUE or FALSE depending on the DOM Tree is a valid Document |
| 62 |
or not. |
| 63 |
|
| 64 |
</p></dd><dt><strong><a name="item_getDocumentElement">getDocumentElement</a></strong></dt><dd><p> |
| 65 |
Returns the root element of the Document. A document can have just one root |
| 66 |
element to contain the documents data. |
| 67 |
|
| 68 |
</p></dd><dt><strong><a name="item_setDocumentElement">setDocumentElement</a></strong></dt><dd><p> |
| 69 |
This function enables you to set the root element for a document. The |
| 70 |
function supports the import of a node from a different document tree. |
| 71 |
|
| 72 |
</p></dd><dt><strong><a name="item_createElement">createElement</a></strong></dt><dd><p> |
| 73 |
This function creates a new Element Node bound to the DOM with the name <em>$nodename</em> . |
| 74 |
|
| 75 |
</p></dd><dt><strong><a name="item_createElementNS">createElementNS</a></strong></dt><dd><p> |
| 76 |
This function creates a new Element Node bound to the DOM with the name <em>$nodename</em> and placed in the given namespace. |
| 77 |
|
| 78 |
</p></dd><dt><strong><a name="item_createTextNode">createTextNode</a></strong></dt><dd><p> |
| 79 |
As an equivalent of <strong>createElement</strong> , but it creates a <strong>Text Node</strong> bound to the DOM. |
| 80 |
|
| 81 |
</p></dd><dt><strong><a name="item_createComment">createComment</a></strong></dt><dd><p> |
| 82 |
As an equivalent of <strong>createElement</strong> , but it creates a <strong>Comment Node</strong> bound to the DOM. |
| 83 |
|
| 84 |
</p></dd><dt><strong><a name="item_createAttribute">createAttribute</a></strong></dt><dd><p> |
| 85 |
Creates a new Attribute node. This function is rather useless at the |
| 86 |
moment, since there is no setAttributeNode function defined in <em>XML::LibXML::Element</em> , yet. |
| 87 |
|
| 88 |
</p></dd><dt><strong><a name="item_createAttributeNS">createAttributeNS</a></strong></dt><dd><p> |
| 89 |
Creates an Attribute bound to a namespace. |
| 90 |
|
| 91 |
</p></dd><dt><strong><a name="item_createCDATASection">createCDATASection</a></strong></dt><dd><p> |
| 92 |
Similar to createTextNode and createComment, this function creates a |
| 93 |
CDataSection bound to the current DOM. |
| 94 |
|
| 95 |
</p></dd><dt><strong><a name="item_importNode">importNode</a></strong></dt><dd><p> |
| 96 |
If a node is not part of a document, it can be imported to another |
| 97 |
document. As specified in DOM Level 2 Specification the Node will not be |
| 98 |
altered or removed from its original document by default. ( <em>$node-</em><code>cloneNode(1)></code> will get called implicitly). Sometimes it is |
| 99 |
necessary to <em>move</em> a node between documents. In such a case the node will not be copied, but |
| 100 |
removed from the original document. |
| 101 |
|
| 102 |
</p></dd></dl><p/><hr/><h1><a name="SEE_ALSO">SEE ALSO</a></h1><p> |
| 103 |
XML::LibXML, XML::LibXML::Element, XML::LibXML::Text, XML::LibXML::Attr, |
| 104 |
XML::LibXML::Comment |
| 105 |
|
| 106 |
</p><p/><hr/><h1><a name="VERSION">VERSION</a></h1><p> |
| 107 |
0.90_a |
| 108 |
|
| 109 |
</p></body></html> |