Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > indented xml using XML::DOM

Reply
Thread Tools

indented xml using XML::DOM

 
 
Parapura Rajkumar
Guest
Posts: n/a
 
      02-09-2009
hey all

I am using XML:om->printToFile to write out an XML:om 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:om object.

Raj
 
Reply With Quote
 
 
 
 
mirod
Guest
Posts: n/a
 
      02-10-2009
Parapura Rajkumar wrote:

> I am using XML:om->printToFile to write out an XML:om 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:om object.


XML:OM 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:OM: these days, XML::LibXML
is the preferred DOM implementation in Perl. It is a lot more powerful than
XML:OM, and more actively maintained AFAIK. It is also quite compatible with
XML:OM, so it is pretty easy to port the code.

--
mirod
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a long XML string into indented format Laguna Python 3 01-26-2006 01:54 PM
Re: Convert a long XML string into indented format mwilliams Python 0 01-25-2006 08:31 PM
Writer required for indented XML output? Ian Pilcher Java 0 08-14-2005 03:19 PM
making indented XML Steve Maring Java 0 01-10-2004 03:13 AM
Newbie: Generating indented XML via Excel-VBA Piet XML 0 08-26-2003 08:28 AM



Advertisments