[xml] A Tool for making an XML file more readable

Date view Thread view Subject view Author view

From: Adam Potolsky (APotolsky@Connex.com)
Date: Fri Dec 15 2000 - 14:48:27 EST


For immediate release under the LGPL from Connex Inc. http://www.connex.com

   Attached is a program I wrote which does a simple XML conversion to a
more human readable format and keep enough information to reverse the
process. New lines found in the XML are converted to &nl; and tabs are
converted to &tab; Please note, by the definition of XML, the output of this
program is _NOT_ the same XML as the file it converted, and heck, it might
not even be legal XML. The same file, however, reversed back through
xml2text will be the same as what went in.

Here is an example:
---------------- Begin Example ----------------
<?xml version="1.0"?>
<root>1<Parent Level="1"
><Child>data</Child><AnotherChild><GrandChild><GreatGrandChild>none</GreatGr
andChild></GrandChild></AnotherChild></Parent></root>
---------------- End Example ----------------
converts to: (Yes, there is a leading newline.)
---------------- Begin Example ----------------

<?xml version="1.0"?>&nl;
<root>1
        <Parent Level="1" >
                <Child>data</Child>
                <AnotherChild>
                        <GrandChild>
                                <GreatGrandChild>none</GreatGrandChild>
                        </GrandChild>
                </AnotherChild>
        </Parent>
</root>&nl;
---------------- End Example ----------------
   The reason for creating this tool is I was working with an XML file which
contained a few levels of depth and number of tags which all ended up on one
line. The file needed to be read and edited for testing, which is very
difficult when there is 6k of text on one line. The tool would convert the
file, I could review and edit, then convert it back and reuse the file.
   I hope people find it useful!

Planned functionality: Add the ability to read directly from stdin. Right
now it reads from a file, and outputs to stdout. Also, I want to remove the
leading new line from the output.

Disclaimer: It's not very robust with DTDs, and that is mainly because the
XML files I deal with do not have DTDs. I tried to add code to the
conversion process that would ignore DTDs as they tend not to be so
inherently difficult to read. (xml2text does not simplify XML, only formats
it... =) I would be happy to continue updating the program if folks want to
contribute changes. I can be emailed at apotolsky@connex.com or
speaker@potolsky.com
 <<xml2text-0.1.tar.gz>>


----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Fri Dec 15 2000 - 15:43:53 EST