Re: [xml] patch for indenting comments/PIs in xmlsave



On Tue, Mar 13, 2007 at 12:50:30PM -0400, Jason Viers wrote:
When saving a new doc using indent, comments and PIs don't get indented 
like elements do:

<?xml version="1.0"?>
<rootNode>
 <item>child1</item>
<!--commentContents-->
 <item>child2</item>
<?name value?>
 <item>child3</item>
</rootNode>


Right now xmlNodeListDumpOutput indents the list item only if it's an 
element.  The patch changes it to indent if it's an element, comment, or 
processing instruction.

Lemme know if there are any problems or questions.

  My main concern would be about reindenting when processed many times but
that seems to work:

paphio:~/XML -> xmllint --format tst.xml | xmllint --format - | xmllint --format -
<?xml version="1.0"?>
<rootNode>
  <item>child1</item>
  <!--commentContents-->
  <item>child2</item>
  <?name value?>
  <item>child3</item>
</rootNode>
paphio:~/XML -> 

Now the problem are comments more than one line long, that looks really weird
now:

paphio:~/XML -> cat tst.xml
<?xml version="1.0"?>
<rootNode>
<item>child1</item>
<!-- this comment has
  1/ one line
  2/ another line
 -->
<item>child2</item>
<?name value?>
<item>child3</item>
</rootNode>

paphio:~/XML -> xmllint --format  tst.xml
<?xml version="1.0"?>
<rootNode>
  <item>child1</item>
  <!-- this comment has
  1/ one line
  2/ another line
 -->
  <item>child2</item>
  <?name value?>
  <item>child3</item>
</rootNode>
paphio:~/XML -> 

  changing the comments textual content is of course not acceptable. So the
improvement is far from systematic, in some case it is worse IMHO

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
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]