XML to XML Transformation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Will

    XML to XML Transformation

    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>200 1</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.
  • Dimitre Novatchev

    #2
    Re: XML to XML Transformation


    "Will" <william.cook@k la-tencor.com> wrote in message
    news:8506d1f6.0 310311244.49a08 56c@posting.goo gle.com...[color=blue]
    > 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.
    >[/color]
    <car><make>ford </make><color>red </color><year>200 1</year></car><car><make> <m
    b>[color=blue]
    > etc. etc. etc. Some lines are over 300 characters long. I need to
    > translate this spagetti XML into something which is humanly readable.[/color]

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

    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:output element.


    =====
    Cheers,

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


    Comment

    • Will Cook

      #3
      Re: XML to XML Transformation


      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!

      Comment

      • Dimitre Novatchev

        #4
        Re: XML to XML Transformation

        > Thanks for your response. My problem is I have to use this XML file as[color=blue]
        > 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.[/color]

        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:styleshe et version="1.0"
        xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

        <xsl:output omit-xml-declaration="ye s" 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>200 1</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







        Comment

        • Michael Wein

          #5
          Re: XML to XML Transformation

          On 31 Oct 2003 12:44:23 -0800, Will wrote:
          [color=blue]
          > I am receiving an XML file which concatenates nodes all on one line i.e.
          > <car><make>ford </make><color>red </color><year>200 1</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.[/color]

          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.
          [color=blue]
          > I probably need to use XSL however I'm not sure what I need to do.
          > Any help will be much appreciated.[/color]

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

          Comment

          • Michael Wein

            #6
            Re: XML to XML Transformation

            On 31 Oct 2003 21:51:07 GMT, Will Cook wrote:
            [color=blue]
            > 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.[/color]

            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

            Comment

            • Will Cook

              #7
              Re: XML to XML Transformation

              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!

              Comment

              • keyur shah

                #8
                Re: XML to XML Transformation

                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!

                Comment

                • Steve Slatcher

                  #9
                  Re: XML to XML Transformation

                  Will Cook wrote:
                  [color=blue]
                  > I looked up
                  > 'identity transformation' in the XML books I have, Handbook 4.0 and
                  > Definitive XML, and couldn't find a reference.[/color]



                  But I think using a browser is the simplest idea. You can collapse
                  everything you don't want to see.


                  Comment

                  Working...