indented xml using XML::DOM

  • Thread starter Parapura Rajkumar
  • Start date
P

Parapura Rajkumar

hey all

I am using XML::Dom->printToFile to write out an XML::Dom document
that I created. Is there a way to indent the output. By default the
whole xml is written out in just one line.

XML::Handler::XMLWriter with newlines option claims to do this but
doesn't take an XML::Dom object.

Raj
 
M

mirod

Parapura said:
I am using XML::Dom->printToFile to write out an XML::Dom document
that I created. Is there a way to indent the output. By default the
whole xml is written out in just one line.

XML::Handler::XMLWriter with newlines option claims to do this but
doesn't take an XML::Dom object.

XML::DOM doesn't seem to provide any mean of pretty printing the output.
Note that in a purely XML context, there is no need for it, and adding
whitespace indiscriminately could even lead to the output becoming invalid (wrt
a DTD).

That said you can always post-process your XML, using xmllint (which comes with
libxml2) or xml_pp (which comes with XML::Twig) for example.

Finally, I have to add a word of caution about XML::DOM: these days, XML::LibXML
is the preferred DOM implementation in Perl. It is a lot more powerful than
XML::DOM, and more actively maintained AFAIK. It is also quite compatible with
XML::DOM, so it is pretty easy to port the code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top