XML to XML Transformation

W

Will

I was thrust into XML about 2 weeks ago and don't know much yet. From
another department in the corp I am receiving an XML file which
concatenates nodes all on one line i.e.
<car><make>ford</make><color>red</color><year>2001</year></car><car><make><mb>
etc. etc. etc. Some lines are over 300 characters long. I need to
translate this spagetti XML into something which is humanly readable.
I probably need to use XSL however I'm not sure what I need to do.
Any help will be much appreciated.
 
D

Dimitre Novatchev

Will said:
I was thrust into XML about 2 weeks ago and don't know much yet. From
another department in the corp I am receiving an XML file which
concatenates nodes all on one line i.e.
etc. etc. etc. Some lines are over 300 characters long. I need to
translate this spagetti XML into something which is humanly readable.

View the xml file using IE or Mozilla -- they provide an appealing,
aesthetic looking layout with collapse/expanding of contents of elements.
I probably need to use XSL however I'm not sure what I need to do.

If you decide to use XSLT (if, because the first approach above is really
what one needs in order to view an xml file), you need to run the identity
transformation, but specify:

indent="yes"

for the xsl:eek:utput element.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
W

Will Cook

Dimitre,
Thanks for your response. My problem is I have to use this XML file as
input to be processed by an application I am writing. It would be much
easier if I could read a line of input which contained a start tag, the
value, the end tag instead of having to parse a 300+ character line
looking for all the various tags used. I looked up 'identity
transformation' in the XML books I have, Handbook 4.0 and Definitive
XML, and couldn't find a reference. Could you be a little more
specific. Sorry for being a pest.
-->Will
 
D

Dimitre Novatchev

Thanks for your response. My problem is I have to use this XML file as
input to be processed by an application I am writing. It would be much
easier if I could read a line of input which contained a start tag, the
value, the end tag instead of having to parse a 300+ character line
looking for all the various tags used. I looked up 'identity
transformation' in the XML books I have, Handbook 4.0 and Definitive
XML, and couldn't find a reference. Could you be a little more
specific. Sorry for being a pest.

The identity transform is defined in the XSLT spec
(http://www.w3.org/TR/xslt#copying):

"For example, the identity transformation can be written using xsl:copy as
follows:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>"

Therefore this transformation:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

when applied (with Saxon 6.5.3) on this source.xml:

<car><make>ford</make><color>red</color><year>2001</year></car>


produces this result:

<car>
<make>ford</make>
<color>red</color>
<year>2001</year>
</car>


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
M

Michael Wein

I am receiving an XML file which concatenates nodes all on one line i.e.
<car><make>ford</make><color>red</color><year>2001</year></car><car><make><mb>
etc. etc. etc. Some lines are over 300 characters long. I need to
translate this spagetti XML into something which is humanly readable.

Then you need a pretty printer/beautifier/code reformatter rather than a
transformation tool! Basically any reasonable XML editor provides such a
feature, e.g. JEdit with the XML plugins.
I probably need to use XSL however I'm not sure what I need to do.
Any help will be much appreciated.

No, I can't recognise where XSL might make sense in your scenario.
 
M

Michael Wein

Thanks for your response. My problem is I have to use this XML file as
input to be processed by an application I am writing.

Then it doesn't have to be human readable as stated in your original
posting but rather machine readable what makes a *huge* difference!

Why not just use a standard XML parser like Xerces, Saxon, ... and access
the file using DOM or SAX APIs? Either I am missing some crucial aspect or
you are lacking basic parsing knowledge.
 
W

Will Cook

Dimitre,
Thank you so very much. With you help the sun is starting to peek
through these XML clouds :)

-->Will
Why Let Reality Wreck Your Day?!?
 
K

keyur shah

Basically, you can simply open your XML file in browsers supporting XML
such as IE and you would be able to see the XML formatted properly as
TAGS.

But, if you want to have the XML formatted in a particular style as
paragraph and so on,, you would need to develop/build an XSL file, and
do a transformation by applying XSL on top of XML in order to make it
formatted and human readable.



Keyur Shah
Verizon Communications
732-423-0745
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top