XML::LibXML::Node - "virtual" Base Class DOM-Nodes
use XML::LibXML
$name = $node->nodeName; $node->setNodeName( $newName ); $bool = $node->isSameNode( $other_node ); $bool = $node->isEqual( $other_node ); $content = $node->nodeValue; $content = $node->textContent; $type = $node->nodeType; $node->unbindNode() $childnode = $node->removeChild( $childnode ) $oldnode = $node->replaceChild( $newNode, $oldNode ) $node->replaceNode($newNode); $childnode = $node->appendChild( $childnode ) $node->addSibling($newNode); $newnode =$node->cloneNode( $deep ) @attrs =$node->attributes; $parentnode = $node->parentNode; $nextnode = $node->nextSibling() $prevnode = $node->previousSibling() $boolean = $node->hasChildNodes(); $childnode = $node->firstChild; $childnode = $node->lastChild; $documentnode = $node->ownerDocument; $node = $node->getOwner; $node->setOwnerDocument( $doc ); $node->insertBefore( $newNode, $refNode ) $node->insertAfter( $newNode, $refNode ) @nodes = $node->findnodes( $xpath_statement ); $result = $node->find( $xpath ); print $node->findvalue( $xpath ); @childnodes = $node->childNodes; $xmlstring = $node->toString($format,$docencoding); $localname = $node->localname; $nameprefix = $node->prefix; $uri = $node->namespaceURI() $boolean = $node->hasAttributes(); @attributelist = $node->attributes(); $nsnode = $node->lookupNamespaceURI( $URI ); $nsnode = $node->lookupNamespacePrefix( $prefix ); $node->iterator( \&nodehandler ); $node->normalize; @nslist = $node->getNamespaces;
LibXML::Node defines functions that are common to all Node Types. A LibXML::Node should never be created standalone, but as an instance of a high level class such as LibXML::Element or LibXML::Text. The class itself should provide only common functionality. In XML::LibXML each node is part either of a document or a document-fragment. Because of this there is no node without a parent. This may causes confusion with "unbound" nodes.
depraced version of isSameNode().
NOTE isEqual will change behaviour to follow the DOM specification
If the node has any content (such as stored in a text node) it can get requested through this function.
NOTE: Element Nodes have no content per definition. To get the text value of an Element use textContent() instead!
This function binds a node to another DOM. This method unbinds the node first, if it is allready bound to another document.
This function is the oposite calling of XML::LibXML::Document's adoptNode() function. Because of this it has the same limitations with Entity References as adoptNode().
findvalue is exactly equivalent to:
$node->find( $xpath )->to_literal; That is, it returns the literal value of the results. This enables you to ensure that you get a string back from your search, allowing certain shortcuts. This could be used as the equivalent of <xsl:value-of select="some_xpath"/>.
This is the equivalent to XML::LibXML::Document::toString for a single node. This means a node and all its childnodes will be dumped into the result string.
Additionally to the $format flag of XML::LibXML::Document, this version accepts the optional $docencoding flag. If this flag is set this function returns the string in its original encoding (the encoding of the document) rather than UTF8.
returns all attributes of a given node
if this function is called in array context the attribute nodes are returned as an array hash.
Find a namespace by its prefix starting at the current node.
NOTE Only the namespace URIs are unique. The prefix is only document related.
This is little helper function, that lets one define a function, that will be processed on the current node and all its children. The function will recieve as its only parameter the node to proceed. The function uses inorder proceeding to traverse the subtree. Therefore you can't reach the childnodes anymore, if the nodehandler removes childnodes.
$node->iterator( sub { print $_[0]->nodeName(),"\n"; } ); The example will print all node names in the current subtree.
The iterator function will return the return value of the nodehandler while processing the last child of the current node.
If a node has any namespaces defined, this function will return these namespaces. Note, that this will not return all namespaces that are in scope, but only the ones declares explicitly for that node.
Although getNamespaces is available for all nodes, it makes only sense if used with element nodes.
Matt Sergeant, Christian Glahn
XML::LibXML, XML::LibXML::Element, XML::LibXML::Text, XML::LibXML::Comment, XML::LibXML::Attr, XML::LibXML::DocumentFragment
1.50