XML-LibXML-LazyBuilder-0.08/000755 000765 000024 00000000000 12054424216 015546 5ustar00torustaff000000 000000 XML-LibXML-LazyBuilder-0.08/Changes000644 000765 000024 00000000466 11772102552 017051 0ustar00torustaff000000 000000 Revision history for Perl extension XML::LibXML::LazyBuilder. 0.02 Sun Nov 9 20:10:18 HST 2008 - fixed required Perl version 0.02 Sun Nov 9 19:35:08 HST 2008 - fixed some meta data 0.01 Wed Nov 5 22:53:37 2008 - original version; created by h2xs 1.23 with options -X -A XML::LibXML::LazyBuilder XML-LibXML-LazyBuilder-0.08/lib/000755 000765 000024 00000000000 12054424216 016314 5ustar00torustaff000000 000000 XML-LibXML-LazyBuilder-0.08/Makefile.PL000644 000765 000024 00000001326 12054423534 017524 0ustar00torustaff000000 000000 use 5.008000; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'XML::LibXML::LazyBuilder', VERSION_FROM => 'lib/XML/LibXML/LazyBuilder.pm', # finds $VERSION PREREQ_PM => {XML::LibXML => 0}, # e.g., Module::Name => 1.1 LICENSE => 'perl', ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/XML/LibXML/LazyBuilder.pm', # retrieve abstract from module AUTHOR => 'Toru Hisai ') : ()), PREREQ_FATAL => 0, dist => { PREOP => 'pod2text lib/XML/LibXML/LazyBuilder.pm > README' }, ); XML-LibXML-LazyBuilder-0.08/MANIFEST000644 000765 000024 00000000432 12054424216 016676 0ustar00torustaff000000 000000 Changes Makefile.PL MANIFEST MANIFEST.SKIP README t/XML-LibXML-LazyBuilder.t lib/XML/LibXML/LazyBuilder.pm t/package.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) XML-LibXML-LazyBuilder-0.08/MANIFEST.SKIP000644 000765 000024 00000000036 11772331646 017455 0ustar00torustaff000000 000000 \.hg \.git .*\.bak ^Makefile$ XML-LibXML-LazyBuilder-0.08/META.json000644 000765 000024 00000001576 12054424216 017200 0ustar00torustaff000000 000000 { "abstract" : "easy and lazy way to create XML documents", "author" : [ "Toru Hisai " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120630", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "XML-LibXML-LazyBuilder", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "XML::LibXML" : "0" } } }, "release_status" : "stable", "version" : "0.08" } XML-LibXML-LazyBuilder-0.08/META.yml000644 000765 000024 00000000772 12054424216 017025 0ustar00torustaff000000 000000 --- abstract: 'easy and lazy way to create XML documents' author: - 'Toru Hisai ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120630' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: XML-LibXML-LazyBuilder no_index: directory: - t - inc requires: XML::LibXML: 0 version: 0.08 XML-LibXML-LazyBuilder-0.08/README000644 000765 000024 00000015661 12054424216 016437 0ustar00torustaff000000 000000 NAME XML::LibXML::LazyBuilder - easy and lazy way to create XML documents 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 This module significantly abridges the overhead of working with XML::LibXML by enabling developers to write concise, nested structures that evaluate into XML::LibXML objects. FUNCTIONS DOM my $doc = DOM (E $name => \%attr, @children), $var, $enc; # With defaults, this is shorthand for: my $doc = E($name => \%attr, @children)->(XML::LibXML::Document->new); Generates a "XML::LibXML::Document" object. The first argument is a "CODE" reference created by "E". $var represents the version in the XML declaration, and $enc is the character encoding, which default to 1.0 and "utf-8", respectively. E my $sub = E tagname => \%attr, @children; my $doc = DOM $sub; This function returns a "CODE" reference which itself evaluates to an XML::LibXML::Element object. The function returned from "E" expects an XML::LibXML::Document object as its only argument, which is conveniently provided by "DOM". Using "E" with an existing XML document "E" can also be used to compose the subtree of an existing XML element. Instead of supplying a name as the first argument of "E", supply an XML::LibXML::Element object. Note, however, that any attributes present in that object will be overwritten by "\%attr", and the supplied element *must* be bound to a document, or the function will croak. This is to ensure that the subtree is connected to the element's document and not some other document. As such, any XML::LibXML::Document object passed into the function returned by "E" will be ignored in favour of the document connected to the supplied element. This also means that "E($elem => \%attr, @children)->($ignored_dom);" can be called in void context, because it will just return $elem. # parse an existing XML document my $doc = XML::LibXML->load_xml(location => 'my.xml'); # find an element of interest my ($existing) = $doc->findnodes('//some-element[1]'); # prepare the subtree my $sub = E $existing => \%attr, @children; # this will overwrite the attributes of $existing and append # @children to it; normally the document is passed as an argument # but in this case it would be derived from $existing. $sub->(); # we also don't care about the output of this function, since it # will have modified $doc, which we already have access to. Note as well that members of @children can be XML::LibXML::Node objects. Namespaces Qualified element names and namespace declaration attributes will behave largely as expected. This means that: E 'foo:bar' => { 'xmlns:foo' => 'urn:x-foo:' }; # ... ...will properly induct the generated element into the "foo" namespace. E attempts to infer the namespace mapping from the document, so child elements with qualified names will inherit the mapping from their ancestors. CAVEAT: When "E" is executed in the context of an *element name* rather than with an existing XML::LibXML::Element, the namespace mappings are scanned from the context of the document root, in document order. This means that the last namespace declaration that appears in the existing document (depth-first) will occupy the given prefix. When an existing element is passed into "E", the namespace search begins there and ascends to the root. If you have any concerns about collisions of namespace declarations, use that form instead. P my $sub = P target => { key => 'value' }, @othertext; This function returns a "CODE" reference which returns a processing instruction. If you pass in a HASH reference as the first argument, it will be turned into key-value pairs using double-quotes on the values. This means you have to take care of your own escaping of any double quotes that may be in the values. The rest of the arguments are concatenated into a string (intended to behave like "print" in perlfunc, which means if you want spaces between them, you likewise need to add them yourself). C my $sub = C @text; This function creates a "CODE" reference which returns a comment. Again, @text is simply concatenated, so if you wish to do any additional formatting, do so before passing it in. D my $sub = D @text; This function creates a "CODE" reference which returns a CDATA section. Works identically to "C". F my $sub = F @children; This function creates a "CODE" reference which returns a document fragment. Since "DOM" can only accept a single node-generating function, it is particularly useful for the following idiom: my $doc = DOM F( (P 'xml-stylesheet' => { type => 'text/xsl', href => '/foo.xsl' }), (E mydoc => {}, @children)); Which produces: ... DTD my $sub = DTD $name => $public, $system; This function creates a "CODE" reference which returns a DTD declaration. Both $public and $system can be "undef". EXPORT None by default. :all Exports "E", "P", "C", "D", "F" and "DOM". EXAMPLES If you nest your code in braces and use a "package" declaration like so, you can avoid polluting the calling package's namespace: 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: Content of DContent of F SEE ALSO XML::LibXML The Python module lxml.etree AUTHOR Toru Hisai Namespace and non-element support by Dorian Taylor COPYRIGHT AND LICENSE Copyright (C) 2008, 2012 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. XML-LibXML-LazyBuilder-0.08/t/000755 000765 000024 00000000000 12054424216 016011 5ustar00torustaff000000 000000 XML-LibXML-LazyBuilder-0.08/t/package.t000644 000765 000024 00000002477 12054304147 017603 0ustar00torustaff000000 000000 # -*- perl -*- # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl XML-LibXML-LazyBuilder.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 3; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. use XML::LibXML::LazyBuilder; # do not import sub E {} sub DOM {} { package XML::LibXML::LazyBuilder; my $d = DOM (E A => {at1 => "val1", at2 => "val2", E => "EEE!"}, ((E B => {}, ((E "C"), (E "D"))), (E E => {}, ((E "F"), (E "G"))))); package main; is ($d->firstChild->firstChild->nextSibling->firstChild->nextSibling->tagName, "G", "package"); is ($d->firstChild->getAttribute ("E"), "EEE!", "package"); } { package XML::LibXML::LazyBuilder; my $d = DOM (E A => {at2 => "val1", at1 => "val2"}, ((E B => {}, ((E "C"), (E D => {}, "Content of D"))), (E E => {}, ((E F => {}, "Content of F"), (E "G"))))); package main; is ($d->toStringC14N, (qq[Content of D] . qq[Content of F]), "example"); } XML-LibXML-LazyBuilder-0.08/t/XML-LibXML-LazyBuilder.t000644 000765 000024 00000004705 11773330732 022163 0ustar00torustaff000000 000000 # -*- perl -*- # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl XML-LibXML-LazyBuilder.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More qw(no_plan); BEGIN { use_ok('XML::LibXML::LazyBuilder') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. use XML::LibXML::LazyBuilder qw/:all/; { my $e = E "hoge"; isa_ok ($e, 'CODE'); my $d = DOM $e; isa_ok ($d, 'XML::LibXML::Document'); is ($d->firstChild->tagName, "hoge", "tag name"); } { my $e = E hoge => {at1 => "val1", at2 => "val2"}; my $d = DOM $e; is ($d->firstChild->getAttribute ("at1"), "val1", "attribute"); is ($d->firstChild->getAttribute ("at2"), "val2", "attribute"); # cloning my $d2 = DOM $e; $d2->firstChild->setAttribute ("at1", "val1'"); is ($d->firstChild->getAttribute ("at1"), "val1", "original"); is ($d2->firstChild->getAttribute ("at1"), "val1'", "clone"); } { my $d = DOM (E (hoge => {}, "content")); is ($d->firstChild->textContent, "content", "text content"); } { my $d = DOM (E A => {}, ((E B => {}, ((E "C"), (E "D"))), (E E => {}, ((E "F"), (E "G"))))); is ($d->firstChild->firstChild->nextSibling->firstChild->nextSibling->tagName, "G", "child nodes"); } { my $d = DOM E 'no-prefix' => { 'xmlns' => 'urn:x-foo:', 'xmlns:bar' => 'urn:x-bar:' }, E 'wat'; #diag($d->toString); is($d->documentElement->namespaceURI, 'urn:x-foo:', 'namespace'); my $e = $d->documentElement; my $sub = E $e => { one => 'two' }, E test => { 'xmlns:test' => 'urn:x-test:' }, E 'test:hello'; my $e2 = $sub->(); #diag($d->toString); is($e->namespaceURI, 'urn:x-foo:', 'propagated namespace'); # XXX should really do way more tests here but effit } { # fragment, processing instruction, DTD, comment, cdata my $d = DOM F( (P 'xml-stylesheet' => { type => 'text/xsl', href => '/foo.xsl' }), (DTD 'foo'), (E foo => { xmlns => 'urn:x-wat:' }, E bar => {}, (C 'yo'), (D 'hi'))); #diag($d->toString(1)); # only really concerned that the namespaces came out ok my $nsuri = $d->documentElement->firstChild->namespaceURI; is($nsuri, 'urn:x-wat:', 'namespace survived fragment'); } XML-LibXML-LazyBuilder-0.08/lib/XML/000755 000765 000024 00000000000 12054424216 016754 5ustar00torustaff000000 000000 XML-LibXML-LazyBuilder-0.08/lib/XML/LibXML/000755 000765 000024 00000000000 12054424216 020043 5ustar00torustaff000000 000000 XML-LibXML-LazyBuilder-0.08/lib/XML/LibXML/LazyBuilder.pm000644 000765 000024 00000036350 12054423656 022645 0ustar00torustaff000000 000000 package XML::LibXML::LazyBuilder; use 5.008000; use strict; use warnings FATAL => 'all'; use Carp (); use Scalar::Util (); use XML::LibXML (); # consider using Exporter::Lite - djt require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use XML::LibXML::LazyBuilder ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( DOM E P C D F DTD ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.08'; # This is a map of all the DOM level 3 node names for # non-element/attribute nodes. Note how there is no provision for # processing instructions. my %NODES = ( '#cdata-section' => 1, '#comment' => 1, '#document' => 1, '#document-fragment' => 1, '#text' => 1, ); # Note this is and will remain a stub until appropriate behaviour can # be worked out. # (Perhaps a name of ?foo for processing instructions?) # nah, special methods for non-element nodes! # Preloaded methods go here. # This predicate is an alternative to using UNIVERSAL::isa as a # function (which is a no-no); it will return true if a blessed # reference is derived from a built-in reference type. sub _is_really { my ($obj, $type) = @_; return unless defined $obj and ref $obj; return Scalar::Util::blessed($obj) ? $obj->isa($type) : ref $obj eq $type; } sub DOM ($;$$) { my ($sub, $ver, $enc) = @_; my $dom = XML::LibXML::Document->new ($ver || "1.0", $enc || "utf-8"); # this whole $dom $sub thing is cracking me up ;) -- djt my $node = $sub->($dom); if (_is_really($node, 'XML::LibXML::DocumentFragment')) { # "Appending a document fragment node to a document node not # supported yet!", says XML::LibXML, so we work around it. for my $child ($node->childNodes) { #warn $child->ownerDocument; $child->unbindNode; if ($child->nodeType == 1) { if (my $root = $dom->documentElement) { unless ($root->isSameNode($child)) { Carp::croak("Trying to insert a second root element"); } } else { $dom->setDocumentElement($child); } } else { $dom->appendChild($child); } } } elsif (_is_really($node, 'XML::LibXML::Element')) { # NO-OP: Elements get attached to the root from inside the E # function so it can access the namespace map. } else { $dom->appendChild($node); } $dom; } sub E ($;$@) { my ($name, $attr, @contents) = @_; return sub { my ($dom, $parent) = @_; # note, explicit namespace declarations in the attribute set # are held separately from actual namespace mappings found # from scanning the document. my (%ns, %nsdecl, %attr, $elem, $prefix); # pull the namespace declarations out of the attribute set if (_is_really($attr, 'HASH')) { while (my ($n, $v) = each %$attr) { if ($n =~ /^xmlns(?::(.*))?$/) { $nsdecl{$1 || ''} = $v; } else { $attr{$n} = $v; } } } if (_is_really($name, 'XML::LibXML::Element')) { # throw an exception if the element is not bound to a # document, which itself should become our new $dom Carp::croak("The supplied element must be bound to a document") unless $dom = $name->ownerDocument; # and of course $name is our new $elem $elem = $name; $name = $elem->nodeName; $prefix = $elem->prefix || ''; # then we don't need to scan the document for namespaces, # but we probably should set it for attributes %ns = map { $elem->lookupNamespacePrefix($_) || '' => $_ } $elem->getNamespaces; } elsif (my $huh = ref $name) { Carp::croak("Expected an XML::LibXML::Element; got $huh instead"); } else { # $name is a string ($prefix) = ($name =~ /^(?:([^:]+):)?(.*)$/); $prefix ||= ''; # XXX what happens if $name isn't a valid QName? $elem = $dom->createElement($name); # check for a document element so we can find existing namespaces if ($parent ||= $dom->documentElement) { # XXX this is naive for my $node ($parent->findnodes('namespace::*')) { $ns{$node->declaredPrefix || ''} = $node->declaredURI; } } else { # do this here to make the tree walkable $dom->setDocumentElement($elem); } } # now do namespaces, overriding if necessary # first with the implicit mapping if ($ns{$prefix}) { $elem->setNamespace($ns{$prefix}, $prefix, 1); } # then with the explicit declarations for my $k (keys %nsdecl) { # activate if the ns matches the prefix $elem->setNamespace($nsdecl{$k}, $k, $k eq $prefix); } # now smoosh the mappings together for the attributes %ns = (%ns, %nsdecl); # NOW do the attributes while (my ($n, $v) = each %attr) { my ($pre, $loc) = ($n =~ /^(?:([^:]+):)?(.*)$/); # it'll probably mess up xpath queries if we explicitly # add namespaces to non-prefixed attributes if ($pre and my $nsuri = $ns{$pre}) { $elem->setAttributeNS($nsuri, $n, $v); } else { $elem->setAttribute($n, $v); } } # and finally child nodes for my $child (@contents) { if (_is_really($child, 'CODE')) { $elem->appendChild ($child->($dom, $elem)); } elsif (_is_really($child, 'XML::LibXML::Node')) { # hey, why not? $elem->appendChild($child); } elsif (my $huh = ref $child) { Carp::croak ("$huh is neither a CODE ref or an XML::LibXML::Node"); } else { $elem->appendTextNode ($child); } } $elem; }; } # processing instruction sub P ($;$@) { my ($target, $attr, @text) = @_; return sub { my $dom = shift; # copy, otherwise this will just keep packing it on if executed # more than once my @t = @text; # turn into k="v" convention if (defined $attr) { if (_is_really($attr, 'HASH')) { my $x = join ' ', map { sprintf '%s="%s"', $_, $attr->{$_} } keys %$attr; unshift @t, $x; } else { unshift @t, $attr; } } return $dom->createProcessingInstruction($target, join '', @t); }; } # comment sub C (;@) { my @text = @_; return sub { my $dom = shift; $dom->createComment(join '', @text); }; } # CDATA sub D (;@) { my @text = @_; return sub { my $dom = shift; $dom->createCDATASection(join '', @text); }; } # document fragment sub F (@) { my @children = @_; return sub { my $dom = shift; my $frag = $dom->createDocumentFragment; for my $child (@children) { # same as E if (_is_really($child, 'CODE')) { $frag->appendChild($child->($dom)); } elsif (_is_really($child, 'XML::LibXML::Node')) { $frag->appendChild($child); } elsif (my $huh = ref $child) { Carp::croak ("$huh is neither a CODE ref or an XML::LibXML::Node"); } else { $frag->appendChild($dom->createTextNode($child)); } } $frag; }; } sub DTD ($;$$) { my ($name, $public, $system) = @_; return sub { my $dom = shift; # must be an XS hiccup; can't just pass these in if they're undef $dom->createExternalSubset($name, $public || undef, $system || undef); }; } 1; __END__ =head1 NAME XML::LibXML::LazyBuilder - easy and lazy way to create XML documents for XML::LibXML =head1 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"))))); } =head1 DESCRIPTION This module significantly abridges the overhead of working with L by enabling developers to write concise, nested structures that evaluate into L objects. =head1 FUNCTIONS =head2 DOM my $doc = DOM (E $name => \%attr, @children), $var, $enc; # With defaults, this is shorthand for: my $doc = E($name => \%attr, @children)->(XML::LibXML::Document->new); Generates a C object. The first argument is a C reference created by C. C<$var> represents the version in the XML declaration, and C<$enc> is the character encoding, which default to C<1.0> and C, respectively. =head2 E my $sub = E tagname => \%attr, @children; my $doc = DOM $sub; This function returns a C reference which itself evaluates to an L object. The function returned from C expects an L object as its only argument, which is conveniently provided by L. =head3 Using C with an existing XML document C can also be used to compose the subtree of an existing XML element. Instead of supplying a name as the first argument of C, supply an L object. Note, however, that any attributes present in that object will be overwritten by C<\%attr>, and the supplied element I be bound to a document, or the function will croak. This is to ensure that the subtree is connected to the element's document and not some other document. As such, any L object passed into the function returned by C will be ignored in favour of the document connected to the supplied element. This also means that C \%attr, @children)-E($ignored_dom);> can be called in void context, because it will just return C<$elem>. # parse an existing XML document my $doc = XML::LibXML->load_xml(location => 'my.xml'); # find an element of interest my ($existing) = $doc->findnodes('//some-element[1]'); # prepare the subtree my $sub = E $existing => \%attr, @children; # this will overwrite the attributes of $existing and append # @children to it; normally the document is passed as an argument # but in this case it would be derived from $existing. $sub->(); # we also don't care about the output of this function, since it # will have modified $doc, which we already have access to. Note as well that members of C<@children> can be L objects. =head3 Namespaces Qualified element names and namespace declaration attributes will behave largely as expected. This means that: E 'foo:bar' => { 'xmlns:foo' => 'urn:x-foo:' }; # ... ...will properly induct the generated element into the C namespace. L attempts to infer the namespace mapping from the document, so child elements with qualified names will inherit the mapping from their ancestors. =over 4 B When C is executed in the context of an I rather than with an existing L, the namespace mappings are scanned from the context of the document root, in document order. This means that the last namespace declaration that appears in the existing document (depth-first) will occupy the given prefix. When an existing element is passed into C, the namespace search begins there and ascends to the root. If you have any concerns about collisions of namespace declarations, use that form instead. =back =head2 P my $sub = P target => { key => 'value' }, @othertext; This function returns a C reference which returns a processing instruction. If you pass in a HASH reference as the first argument, it will be turned into key-value pairs using double-quotes on the values. This means you have to take care of your own escaping of any double quotes that may be in the values. The rest of the arguments are concatenated into a string (intended to behave like L, which means if you want spaces between them, you likewise need to add them yourself). =head2 C my $sub = C @text; This function creates a C reference which returns a comment. Again, C<@text> is simply concatenated, so if you wish to do any additional formatting, do so before passing it in. =head2 D my $sub = D @text; This function creates a C reference which returns a CDATA section. Works identically to L. =head2 F my $sub = F @children; This function creates a C reference which returns a document fragment. Since L can only accept a single node-generating function, it is particularly useful for the following idiom: my $doc = DOM F( (P 'xml-stylesheet' => { type => 'text/xsl', href => '/foo.xsl' }), (E mydoc => {}, @children)); Which produces: ... =head2 DTD my $sub = DTD $name => $public, $system; This function creates a C reference which returns a DTD declaration. Both C<$public> and C<$system> can be C. =head1 EXPORT None by default. =head2 :all Exports L, L

, L, L, L and L. =head1 EXAMPLES If you nest your code in braces and use a C declaration like so, you can avoid polluting the calling package's namespace: 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, C<< $d->toString >> will generate XML like this: Content of DContent of F =head1 SEE ALSO L The Python module L =head1 AUTHOR L Namespace and non-element support by L =head1 COPYRIGHT AND LICENSE Copyright (C) 2008, 2012 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. =cut