You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "David R." <da...@hotmail.com> on 2002/05/23 15:36:47 UTC
Pretty printing a DOM tree
I am using a piece of code extracted from the DOMPrint sample in order to
dump a DOM tree into a XML file. I have also taken a look at the serializer
at the following address:
http://www.xs4all.nl/~ewh/DOMSerializer
Both solutions generate a XML file which is very difficult to be read by a
human. Does anybody know of a solution to generate a formatted output?
IMHO, there are two ways to get a pretty print:
a) Adding "text nodes" between every two "element nodes" in the DOM tree
(either having a sibling relation or parent/child relation). The value of
the text node should be a carriage return ("\n") followed by a number of
blank spaces (" ") depending on the indentation of every line in the XML
file. After that, the DOM tree would be dumped into the XML file.
b) Reformating the XML file by using a program which takes an XML file, and
after some processing it writes into another different XML file. In that
case, any change in the DOM tree would require dumping and reformatting
again.
I am not sure if you will understand what I mean. I have not found any
previous work on that subject, so any hints would be appreciated.
Thanks in advance,
David Ruana
_________________________________________________________________
MSN Photos es la manera más sencilla de compartir e imprimir sus fotos:
http://photos.msn.com/support/worldwide.aspx
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Pretty printing a DOM tree
Posted by Robert Buck <rb...@mathworks.com>.
There are lots of examples on the web for "pretty print" serializers. Do a
search at google. They all are basically the same and work well.
Bob
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: Pretty printing a DOM tree
Posted by Evert Haasdijk <ev...@zukkespijkers.nl>.
David,
You can try using the attached code to prettify the DOM.
Hope this helps,
Evert
> -----Original Message-----
> From: David R. [mailto:dakotasiux@hotmail.com]
> Sent: Thursday, May 23, 2002 3:37 PM
> To: xerces-c-dev@xml.apache.org
> Subject: Pretty printing a DOM tree
>
>
>
> I am using a piece of code extracted from the DOMPrint sample in order to
> dump a DOM tree into a XML file. I have also taken a look at the
> serializer
> at the following address:
> http://www.xs4all.nl/~ewh/DOMSerializer
>
> Both solutions generate a XML file which is very difficult to be
> read by a
> human. Does anybody know of a solution to generate a formatted output?
>
> IMHO, there are two ways to get a pretty print:
>
> a) Adding "text nodes" between every two "element nodes" in the DOM tree
> (either having a sibling relation or parent/child relation). The value of
> the text node should be a carriage return ("\n") followed by a number of
> blank spaces (" ") depending on the indentation of every line
> in the XML
> file. After that, the DOM tree would be dumped into the XML file.
>
> b) Reformating the XML file by using a program which takes an XML
> file, and
> after some processing it writes into another different XML file. In that
> case, any change in the DOM tree would require dumping and reformatting
> again.
>
> I am not sure if you will understand what I mean. I have not found any
> previous work on that subject, so any hints would be appreciated.
>
> Thanks in advance,
> David Ruana
>
>
> _________________________________________________________________
> MSN Photos es la manera más sencilla de compartir e imprimir sus fotos:
> http://photos.msn.com/support/worldwide.aspx
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
>