NAME
XML::LibXML::LazyBuilder - easy and lazy way to create XML document for XML::LibXML
SYNOPSIS
use XML::LibXML::LazyBuilder;
{
package XML::LibXML::LazyBuilder;
$d = DOM (E A => {at1 => "val1", at2 => "val2"},
((E B => {}, ((E "C"),
(E D => {}, "Content of D"))),
(E E => {}, ((E F => {}, "Content of F"),
(E "G")))));
}
DESCRIPTION
You can describe XML documents like simple function call instead of using createElement, appendChild, etc...
FUNCTIONS
- E
-
E "tagname", \%attr, @childrenCreats CODEREF that generates
XML::LibXML::Elementwhich tag name is given by first argument. Rest arguments are list of text content or child element created byE(so you can nestE).Since the output of this function is CODEREF, the creation of actual
XML::LibXML::Elementobject will be delayed untilDOMfunction is called. - DOM
-
DOM \&docroot, $var, $encGenerates
XML::LibXML::Documentobject actually. First argument is a CODEREF created byEfunction.$varis version number of XML docuemnt,"1.0"by default.$encis encoding,"utf-8"by default.
EXPORT
None by default.
EXAMPLES
I recommend to use package statement in a small scope so that you can use short function name and avoid to pollute global name space.
my $d;
{
package XML::LibXML::LazyBuilder;
$d = DOM (E A => {at1 => "val1", at2 => "val2"},
((E B => {}, ((E "C"),
(E D => {}, "Content of D"))),
(E E => {}, ((E F => {}, "Content of F"),
(E "G")))));
}
Then, $d->toString will generate XML like this:
<?xml version="1.0" encoding="utf-8"?>
<A at1="val1" at2="val2"><B><C/><D>Content of D</D></B><E><F>Content of F</F><G/></E></A>
SEE ALSO
AUTHOR
Toru Hisai, <toru@torus.jp>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Toru Hisai
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.