roman has asked for the wisdom of the Perl Monks concerning the following question:
does anyone know how to simply solve following annoyance (not a real problem)?
Building DOM by XML::LibXML I create new elements via createElementNS method of XML document. When such document is serialized, every element contains the namespace declaration. Due to this declarations, the document is not very readable and occupies too much space on my screen.
Is there a way how to get rid of these declarations in resulting document and left only those "necessary" (in document element).
The result isuse strict; use warnings; use XML::LibXML; my $ns = 'http://www.example.com'; my $doc = XML::LibXML::Document->new; $doc->setDocumentElement($doc->createElementNS($ns, 'q:one')); $doc->documentElement->appendChild($doc->createElementNS($ns, 'q:two') +); $doc->documentElement->appendChild($doc->createElementNS($ns, 'q:three +')); warn $doc->toString(1);
<?xml version="1.0"?> <q:one xmlns:q="http://www.example.com"> <q:two xmlns:q="http://www.example.com"/> <q:three xmlns:q="http://www.example.com"/> </q:one>
Thanks for any advice
Roman
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::LibXML and too many namespace declarations
by guliver (Friar) on Mar 27, 2007 at 10:43 UTC | |
by roman (Monk) on Mar 27, 2007 at 11:03 UTC |