Re: [xml] XML output formatting



On Wed, Mar 20, 2002 at 11:38:06AM -0500, Wei Qin wrote:

I am generating an XML file with libxml2. I use xmlSaveFile(). But There
is no line break on the output. Do I have to create text node in the tree
with "\n" so as to see the line breaks? Or is there some auto-format
utilities that I can use?

  Check
     http://bugzilla.gnome.org/show_bug.cgi?id=75244

You can use xmllint --format

paphio:~/XML -> cat tst.xml 
<doc><a>
<b><c>foo
</c>

</b>
</a></doc>
paphio:~/XML -> ./xmllint --format tst.xml 
<?xml version="1.0"?>
<doc>
  <a>
    <b>
      <c>foo
</c>
    </b>
  </a>
</doc>
paphio:~/XML -> 
 
At the C level you need to either:
    set
      xmlIndentTreeOutput = 1;
    or call
      xmlKeepBlanksDefault(0);

to have indentation and not just line break added.
Note also that libxml2 will not indent or add linebreak within elements
which are mixed content.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]