NAME

XML::DOM::BagOfTricks - Convenient XML DOM

SYNOPSIS

use XML::DOM::BagOfTricks;

# get the XML document and root element
my ($doc,$root) = getDocument('Foo');

# or

# get the XML document with xmlns and version attributes specified
my $doc = getDocument({name=>'Foo', xmlns=>'http://www.other.org/namespace', version=>1.3});

# get a text element like <Foo>Bar</Bar>
my $node = getTextElement($doc,'Foo','Bar');

# get an element like <Foo isBar="0" isFoo="1"/>
my $node = getElement($doc,'Foo','isBar'=>0, 'isFoo'=>1);

# get a nice element with attributes that contains a text node <Foo isFoo="1" isBar="0">Bar</Foo>
my $foo_elem = getElementwithText($DOMDocument,'Foo','Bar',isFoo=>1,isBar=>0);

DESCRIPTION

XML::DOM::BagOfTricks provides a bundle, or bag, of functions that make dealing with and creating DOM objects easier.

getTextContents() from 'Effective XML processing with DOM and XPath in Perl' by Parand Tony Darugar, IBM Developerworks Oct 1st 2001

getTextElement($doc,$name,$value)

This function returns a nice XML::Xerces::DOMNode representing an element
with an appended Text subnode, based on the arguments provided.

In the example below $node would represent '<Foo>Bar</Foo>'

my $node = getTextElement($doc,'Foo','Bar');

More useful than a pocketful of bent drawing pins! If only the Chilli Peppers
made music like they used to 'Zephyr' is no equal of 'Fight Like A Brave' or
'Give it away'

getElement($doc,$name,%attributes)

This function returns a nice XML::Xerces::DOMNode representing an element
with an appended Text subnode, based on the arguments provided.

In the example below $node would represent '<Foo isBar='0' isFoo='1'/>'

my $node = getElement($doc,'Foo','isBar'=>0, 'isFoo'=>1);

getElementwithText($DOMDocument,$node_name,$text,$attr_name=>$attr_value);

# get a nice element with attributes that contains a text node ( i.e. <Foo isFoo='1' isBar='0'>Bar</Foo> )
my $foo_elem = getElementwithText($DOMDocument,'Foo','Bar',isFoo=>1,isBar=>0);

getDocument($namespace,$root_tag)

This function will return a nice XML:DOM::Document object, if called in array context it will return a list of the Document and the root.

It requires a root tag, and a list of tags to be added to the document

the tags can be scalars :

my ($doc,$root) = getDocument('Foo', 'Bar', 'Baz');

or a hashref of attributes, and the tags name :

my $doc = getDocument({name=>'Foo', xmlns=>'http://www.other.org/namespace', version=>1.3}, 'Bar', 'Baz');

getTextContents($node)

returns the text content of a node (and its subnodes)

my $content = getTextContents($node);

Function by P T Darugar, published in IBM Developerworks Oct 1st 2001

EXPORT

:all

&getTextContents &getDocument &getTextElement &getElement &getElementwithText

SEE ALSO

XML:DOM

XML::Xerces

XML::Xerces::BagOfTricks

AUTHOR

Aaron Trevena, <teejay@droogs.org>

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Aaron Trevena Copyright (c) 2001 Parand Tony Darugar, where applicable

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.