XML::LibXML::Element - The DOM Element Class
use XML::LibXML
$node = XML::LibXML::Element->new( $name ) $node->setAttribute( $aname, $avalue ); $node->setAttributeNS( $nsURI, $aname, $avalue ); $avalue = $node->getAttribute( $aname ); $avalue = $node->setAttributeNS( $nsURI, $aname ); $attrnode = $node->getAttributeNode( $aname ); $attrnode = $node->getAttributeNodeNS( $namespaceURI, $aname ); $node->removeAttribute( $aname ); $node->removeAttributeNS( $nsURI, $aname ); $boolean = $node->hasAttribute( $aname ); $boolean = $node->hasAttributeNS( $nsURI, $aname ); @nodes = $node->getChildrenByTagName($tagname); @nodes = $node->getChildrenByTagNameNS($nsURI,$tagname); @nodes = $node->getElementsByTagName($tagname); @nodes = $node->getElementsByTagNameNS($nsURI,$localname); @nodes = $node->getElementsByLocalName($localname); $node->appendWellBalancedChunk( $chunk ) $node->appendText( $PCDATA ); $node->appendTextNode( $PCDATA ); $node->appendTextChild( $childname , $PCDATA ) $node->setNamespace( $nsURI , $nsPrefix, $activate )
The function gives direct access to all childnodes of the current node with the same tagname. It makes things a lot easier if you need to handle big datasets.
If this function is called in SCALAR context, it returns the number of Elements found.
Namespace version of getChildrenByTagName.
If this function is called in SCALAR context, it returns the number of Elements found.
This function is part of the spec it fetches all descendants of a node with a given tagname. If one is as confused with tagname as I was, tagname is a qualified tagname which is in case of namespace useage prefix and local name
In SCALAR context this function returns a XML::LibXML::NodeList object.
Namespace version of getElementsByTagName as found in the DOM spec.
In SCALAR context this function returns a XML::LibXML::NodeList object.
This function is not found in the DOM specification. It is a mix of getElementsByTagName and getElementsByTagNameNS. It will fetch all tags matching the given local-name. This alows one to select tags with the same local name across namespace borders.
In SCALAR context this function returns a XML::LibXML::NodeList object.
setNamespace() allows one to apply a namespace to an element. The function takes three parameters: 1. the namespace URI, which is required and the two optional values prefix, which is the namespace prefix, as it should be used in child elements or attributes as well as the additionally activate parameter.
The activate parameter is most usefull: If this parameter is set to FALSE (0), the namespace is simply added to the namespacelist of the node, while the element's namespace itself is not altered. Nevertheless activate is set to TRUE (1) on default. In this case the namespace automaticly is used as the nodes effective namespace. This means the namespace prefix is added to the node name and if there was a namespace already active for the node, this will be replaced (but not removed from the global namespace list)
The following example may clarify this:
my $e1 = $doc->createElement("bar"); $e1->setNamespace("http://foobar.org", "foo") results
while my $e2 = $doc->createElement("bar"); $e2->setNamespace("http://foobar.org", "foo",0) results only
By using $activate == 0 it is possible to apply multiple namepace declarations to a single element.
Alternativly you can call setAttribute() simply to declare a new namespace for a node, without activating it:
$e2->setAttribute( "xmlns:foo", "http://bar.org" ); has the same result as
$e2->setNamespace("http://foobar.org", "foo", 0)
Matt Sergeant, Christian Glahn
XML::LibXML, XML::LibXML::Node, XML::LibXML::Document, XML::LibXML::Attr, XML::LibXML::Text, XML::LibXML::Comment, XML::LibXML::DocumentFragment
1.50