XML::LibXML::Tools - An API for easy XML::LibXML DOM manipulation |
XML::LibXML::Tools - An API for easy XML::LibXML DOM manipulation
use XML::LibXML::Tools;
my $lxt = XML::LibXML::Tools->new();
# set croakOnError => 0 for all new objects. $XML::LibXML::Tools::croak = 0;
my $dom = $lxt->complex2Dom( data => [ document => [ node => [ deeper_content => [ $tools->attribute("attribute", "value"), "deep content" ], ], node => [ "content" ] ] ] );
# change content $tools->domUpdate( xpath => "/document/node", data => [ deeper_content => "Other content" ]);
# add comment $tools->domAdd( xpath => "/document", data => [ $tools->comment("blaaa") ]);
# add a nodeset. $tools->domAdd( xpath => "/document/node[2]", location => AFTER, data => [ $dom->findnodes("/document/node[1]") ]);
# add a DOM $tools->domAdd ( xpath => "/document/node[1]", location => BEFORE, data => [ node => [ $otherDom ] ] );
# delete some nodes $tools->domDelete( xpath => "/document", deleteXPath => "./node[1]" );
Hands an interface for merging, updating, adding and deleting a the XML::LibXML::Document manpage in an easy fashion.
Constants are exported for your ease.
BEFORE => "before"; AFTER => "after"; TO => "to";
All these constants can be used for the location parameter
Methods are all accessors, they are show with their default value.
Default adding location.
Filled by complex2Dom if not yet defined, or you.
Used so that you can skip the dom-parameter for each function which is meant to work at this DOM.
If set to 0 complex2Dom doesn't fill the objectDom so you can manipulate 'externals' DOMs without to much overhead.
Set to 1 by addError
Holds the message stack
If an error occurs, croak (errorMsg)
warns the names of the functions called. Not very usefull unless you are an expert
Most of these functions operate parameter based,
eg: $lxt->domAdd(node => $node, dom => $dom, data => $ref )
Most of these functions call upon each other. They always pass their parameters.
The L<XML::LibXML::Document> you want to perform your operation on. If ommited objectDom is tried.
The node on which you wish to perform your operation.
If the node is ommited, uses this xpath-statement to get to a node.
[ element => "of surprise" ]
OR
[ $dom ]
OR
[ $nodelist ]
OR
[ [ element => [ $nodelist ], element => [ $dom ], element => [ attribute( "name", "value" ), "content" ] ]
The data for the operation. Can be an intrigate combination of arrays DOMs and NodeLists
The location for adding.
TO : Add to the selected node BEFORE : insert before the selected node AFTER : insert after the selected node
Used in domDelete. Delete everything that complies to deleteXPath from the selected node.
delete is shorthand
Set the showpath for this operation.
Used internally for showPath. Please do not meddle with it unless your an expert.
For the sake of easy reading '*name' is a parameter.
All these functions return undef once an error has been raised.
DESCRIPTION Turns an array reference into a L<XML::LibXML::Document>, taking array->[0] as the rootname. calls array2Dom for this purpose.
The newly created DOM's encoding is set to be UTF-8
DESCRIPTION Turns *data into a L<XML::LibXML::DocumentFragment> (or alike) so that it can be attached to the *dom or *node at a later point in time. Expert use only.
REQUIRED PARAMETERS dom, node, data
NOTE *xpath is ignored here *node is intrepreted as a parentNode.
DESCRIPTION Update the selected *node with *data by replacing or adding nodes along the way.
REQUIRED PARAMETERS dom, node OR xpath, data
DESCRIPTION Add *data to *node at *location
REQUIRED PARAMETERS dom, node OR xpath, data
DESCRIPTION Delete everything from *deleteXPath from *node. Because this is XPath driven there is no way to remove comments - still looking into a solution for that.
REQUIRED PARAMETERS dom, node OR xpath, data, deleteXPath
returns 'parot', 2, '/newlsetter[1]/section[2]'
returns the special attribute notation for arrays which need to be transformed to DOMs
returns the special comment notation for arrays which need to be transformed to DOMs
Puts a space before and after the comment it is not there, since yours truly beliefs that is more beatifull.
Adds $message to the message stack. Sets error() to 1
Resets the error stack and flag.
0.71 - released 0.72 - minor documentation changes. (it broke on CPAN ... :( )
0.80 - made sure this also works with a 'broken' Text::Iconv
- Encoding:
+ It is expected that you supply your data in the same encoding as is your DOM.
- Unfixed checking problem. You might see something like: complex2Dom: To complex! ...
FIX : Surround the stuff in *data with extra [ ].
Originally Written by Robert Bakker as an Exporter.
Then re-written by Hartog de Mik to: beautify code. chop up into functions.
Then finaly re-written by Hartog de Mik into the current OO implementation
XML::LibXML::Tools - An API for easy XML::LibXML DOM manipulation |