XML to XML Transformation

Discussion in 'XML' started by Will, Oct 31, 2003.

  1. Will

    Will Guest

    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.
    Will, Oct 31, 2003
    #1
    1. Advertising

  2. "Will" <> wrote in message
    news:...
    > 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><m
    b>
    > 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
    Dimitre Novatchev, Oct 31, 2003
    #2
    1. Advertising

  3. Will

    Will Cook Guest

    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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Will Cook, Oct 31, 2003
    #3
  4. > 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
    Dimitre Novatchev, Nov 1, 2003
    #4
  5. Will

    Michael Wein Guest

    On 31 Oct 2003 12:44:23 -0800, Will wrote:

    > 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.
    --
    Michael Wein
    Michael Wein, Nov 3, 2003
    #5
  6. Will

    Michael Wein Guest

    On 31 Oct 2003 21:51:07 GMT, Will Cook wrote:

    > 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.
    --
    Michael Wein
    Michael Wein, Nov 3, 2003
    #6
  7. Will

    Will Cook Guest

    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?!?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Will Cook, Nov 3, 2003
    #7
  8. Will

    keyur shah Guest

    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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    keyur shah, Nov 3, 2003
    #8
  9. Will Cook wrote:

    > I looked up
    > 'identity transformation' in the XML books I have, Handbook 4.0 and
    > Definitive XML, and couldn't find a reference.


    http://www.dpawson.co.uk/xsl/sect2/identity.html

    But I think using a browser is the simplest idea. You can collapse
    everything you don't want to see.
    Steve Slatcher, Nov 7, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugo Ferreira
    Replies:
    0
    Views:
    363
    Hugo Ferreira
    Jul 14, 2004
  2. =?Utf-8?B?YW5kcmV3MDA3?=

    xml transformation convert "<" or ">" value to &lt or &gt

    =?Utf-8?B?YW5kcmV3MDA3?=, Nov 1, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    7,086
    Kevin Spencer
    Nov 1, 2005
  3. yannicklaclau
    Replies:
    2
    Views:
    525
    yannicklaclau
    Feb 28, 2005
  4. HL
    Replies:
    2
    Views:
    402
  5. Binaryx
    Replies:
    3
    Views:
    5,048
    Peter Flynn
    Apr 14, 2012
Loading...

Share This Page