The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::EasySQL::XMLobj::Node - Node interface. Derived from a fork of Robert Hanson's killer XML::EasyOBJ module, which offers Easy XML object navigation

VERSION

Version 1.2

METHODS

makeNewNode( NEW_TAG )

Append a new element node to the current node. Takes the tag name as the parameter and returns the created node as a convienence.

 my $p_element = $doc->body->makeNewNode('p');

getString( )

Recursively extracts text from the current node and all children element nodes. Returns the extracted text as a single scalar value.

_extractText( )

Utility method. Don't call this and don't overload it.

setString( STRING )

Sets the text value of the specified element. This is done by first removing all text node children of the current element and then appending the supplied text as a new child element.

Take this XML fragment and code for example:

<p>This elment has <b>text</b> and <i>child</i> elements</p>

 $doc->p->setString('This is the new text');

This will change the fragment to this:

<p><b>text</b><i>child</i>This is the new text</p>

Because the <b> and <i> tags are not text nodes they are left unchanged, and the new text is added at the end of the specified element.

If you need more specific control on the change you should either use the getDomObj() method and use the DOM methods directly or remove all of the child nodes and rebuild the <p> element from scratch. Also see the addString() method.

addString( STRING )

Adds to the the text value of the specified element. This is done by appending the supplied text as a new child element.

Take this XML fragment and code for example:

<p>This elment has <b>text</b></p>

 $doc->p->addString(' and elements');

This will change the fragment to this:

<p>This elment has <b>text</b> and elements</p>

getAttr( ATTR_NAME )

Returns the value of the named attribute.

 my $val = $doc->body->img->getAttr('src');

getTagName( )

Returns the tag name of the specified element. This method is useful when you are enumerating child elements and do not know their element names.

 foreach my $element ( $doc->getElement() ) {
    print $element->getTagName();
 }

setAttr( ATTR_NAME, ATTR_VALUE, [ATTR_NAME, ATTR_VALUE]... )

For each name/value pair passed the attribute name and value will be set for the specified element.

remAttr( ATTR_NAME )

Removes the specified attribute from the current element.

remElement( TAG_NAME, INDEX )

Removes a child element of the current element. The name of the child element and the index must be supplied. An index of 0 will remove the first occurance of the named element, 1 the second, 2 the third, etc.

getElement( TAG_NAME, INDEX )

Returns the node from the tag name and index. If no index is given the first child with that name is returned. Use this method when you have element names that include characters that are not legal as a perl method name. For example:

 <foo> <!-- root element -->
  <bar>
   <foo-bar>test</foo-bar>
  </bar>
 </foo>

 # "foo-bar" is not a legal method name
 print $doc->bar->getElement('foo-bar')->getString();

getDomObj( )

Returns the DOM object associated with the current node. This is useful when you need fine access via the DOM to perform a specific function.