indented xml using XML::DOM

Discussion in 'Perl Misc' started by Parapura Rajkumar, Feb 9, 2009.

  1. 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
    Parapura Rajkumar, Feb 9, 2009
    #1
    1. Advertising

  2. Parapura  Rajkumar

    mirod Guest

    Parapura Rajkumar wrote:

    > 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.

    --
    mirod
    mirod, Feb 10, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Maring

    making indented XML

    Steve Maring, Jan 10, 2004, in forum: Java
    Replies:
    0
    Views:
    597
    Steve Maring
    Jan 10, 2004
  2. Ian Pilcher
    Replies:
    0
    Views:
    393
    Ian Pilcher
    Aug 14, 2005
  3. Piet
    Replies:
    0
    Views:
    1,052
  4. YGUEL
    Replies:
    1
    Views:
    432
    Manuel Yguel
    Feb 17, 2004
  5. Laguna
    Replies:
    3
    Views:
    2,376
    Paul Boddie
    Jan 26, 2006
Loading...

Share This Page