Menu

How to format XML-Source consistently

Michael
2008-09-05
2012-11-13
  • Michael

    Michael - 2008-09-05

    Hi,

    I want to format a 45.000-line XML-document consistently (one tab-depth for each knot).
    In the moment the file is barely readable and I have to compare versions. The correct (identical) format would make it a lot easier for me.

    Thank you

     
    • Gadrin

      Gadrin - 2008-09-11

      Rather than build a macro for N++ you might want to use a command line tool like XMLStarlet (which is also from Soureforge).

      It can "pretty" flat XML with indentation. It's free so you can test drive it.

      There's also others like HTMLTidy which offers script, COM and GUI options. Also free.

      I think even MSHTML offers a free vbscript already written which will also pretty it, if you've got Windows.

      Probably 10 times easier than writing a N++ script to do it, depending on your skills ;)

      http://sourceforge.net/project/showfiles.php?group_id=66612

      XMLStarlet Toolkit: Format XML document
      Usage: xml fo [<options>] <xml-file>
      where <options> are
         -n or --noindent            - do not indent
         -t or --indent-tab          - indent output with tabulation
         -s or --indent-spaces <num> - indent output with <num> spaces
         -o or --omit-decl           - omit xml declaration <?xml version="1.0"?>
         -R or --recover             - try to recover what is parsable
         -D or --dropdtd             - remove the DOCTYPE of the input docs
         -C or --nocdata             - replace cdata section with text nodes
         -N or --nsclean             - remove redundant namespace declarations
         -e or --encode <encoding>   - output in the given encoding (utf-8, unicode...)
         -H or --html                - input is HTML
         -h or --help                - print help

      XMLStarlet is a command line toolkit to query/edit/check/transform
      XML documents (for more information see http://xmlstar.sourceforge.net/\)

      You can google for HTMLTidy. The VBScript for MSHTML comes with their help file.

      >