Simple way to go from xml to simple text format

Discussion in 'XML' started by mathieu, Jan 6, 2007.

  1. mathieu

    mathieu Guest

    Hello,

    I have the following xml file:

    <Elements>
    <Element>
    <A>1235</A>
    <B>Hello</B>
    </Element>
    ...
    </Elements>

    I would like to produce a text file containing each Element per line
    (xml element being separated let say by a whitespace).

    $ cat out.txt
    12345 Hello
    ....

    The correct solution would be to use fop and write an xsl document,
    right ? Thanks for pointer to 'Hello World' example.

    Regards,
    Mathieu
     
    mathieu, Jan 6, 2007
    #1
    1. Advertising

  2. * mathieu wrote in comp.text.xml:
    > I have the following xml file:
    >
    ><Elements>
    > <Element>
    > <A>1235</A>
    > <B>Hello</B>
    > </Element>
    > ...
    ></Elements>
    >
    >I would like to produce a text file containing each Element per line
    >(xml element being separated let say by a whitespace).
    >
    >$ cat out.txt
    >12345 Hello
    >...
    >
    > The correct solution would be to use fop and write an xsl document,
    >right ? Thanks for pointer to 'Hello World' example.


    XSLT would probably be a simple solution, yes. Note though that Apache
    FOP is a XSL Formatting Objects Processor, it's useful if you want to
    make complex graphical layouts, not for plain text. For XSLT tutorials,
    try a search engine of your choice.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Jan 6, 2007
    #2
    1. Advertising

  3. mathieu

    mathieu Guest

    Re: Simple way to go from xml to simple text format (fop -txt ?)

    Bjoern Hoehrmann wrote:
    > * mathieu wrote in comp.text.xml:
    > > I have the following xml file:
    > >
    > ><Elements>
    > > <Element>
    > > <A>1235</A>
    > > <B>Hello</B>
    > > </Element>
    > > ...
    > ></Elements>
    > >
    > >I would like to produce a text file containing each Element per line
    > >(xml element being separated let say by a whitespace).
    > >
    > >$ cat out.txt
    > >12345 Hello
    > >...
    > >
    > > The correct solution would be to use fop and write an xsl document,
    > >right ? Thanks for pointer to 'Hello World' example.

    >
    > XSLT would probably be a simple solution, yes. Note though that Apache
    > FOP is a XSL Formatting Objects Processor, it's useful if you want to
    > make complex graphical layouts, not for plain text. For XSLT tutorials,
    > try a search engine of your choice.


    Thanks Björn this is really helpful. Unfortunately there is very
    little help on the web when it come to outputing text file. So far I
    have (*). But the command using fop does not output anything:

    $ fop -xml dummy.xml -xsl dummy.xsl -txt out.txt

    Thanks again !
    Mathieu

    (*)
    $ cat dummy.xsl

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <xsl:for-each select="Elements/Element">
    <xsl:value-of select="//A"/>
    <xsl:text>
    </xsl:text><!--produce a newline -->
    <xsl:value-of select="//B"/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    $ cat dummy.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
    <Elements>
    <Element>
    <A>1235</A>
    <B>Hello</B>
    </Element>
    <Element>
    <A>4567</A>
    <B>World</B>
    </Element>
    </Elements>
     
    mathieu, Jan 6, 2007
    #3
  4. mathieu

    mathieu Guest

    Re: Simple way to go from xml to simple text format (fop -txt ?)

    mathieu wrote:
    > Bjoern Hoehrmann wrote:
    > > * mathieu wrote in comp.text.xml:
    > > > I have the following xml file:
    > > >
    > > ><Elements>
    > > > <Element>
    > > > <A>1235</A>
    > > > <B>Hello</B>
    > > > </Element>
    > > > ...
    > > ></Elements>
    > > >
    > > >I would like to produce a text file containing each Element per line
    > > >(xml element being separated let say by a whitespace).
    > > >
    > > >$ cat out.txt
    > > >12345 Hello
    > > >...
    > > >
    > > > The correct solution would be to use fop and write an xsl document,
    > > >right ? Thanks for pointer to 'Hello World' example.

    > >
    > > XSLT would probably be a simple solution, yes. Note though that Apache
    > > FOP is a XSL Formatting Objects Processor, it's useful if you want to
    > > make complex graphical layouts, not for plain text. For XSLT tutorials,
    > > try a search engine of your choice.

    >
    > Thanks Björn this is really helpful. Unfortunately there is very
    > little help on the web when it come to outputing text file. So far I
    > have (*). But the command using fop does not output anything:
    >
    > $ fop -xml dummy.xml -xsl dummy.xsl -txt out.txt


    Nevermind xsltproc worked out of the box, I'll use this tool instead.

    $ xsltproc dummy.xsl dummy.xml

    Sorry for the noise,
    Mathieu
     
    mathieu, Jan 6, 2007
    #4
    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. Brian Candy
    Replies:
    2
    Views:
    1,172
    Janaka
    Feb 18, 2004
  2. =?UTF-8?b?5byg6Z+h5q2m?=
    Replies:
    8
    Views:
    423
    =?UTF-8?b?5byg6Z+h5q2m?=
    Oct 20, 2006
  3. Dominik
    Replies:
    4
    Views:
    2,402
    Dominik
    Mar 22, 2007
  4. Erik Wasser
    Replies:
    5
    Views:
    464
    Peter J. Holzer
    Mar 5, 2006
  5. py
    Replies:
    4
    Views:
    432
    rickman
    Nov 5, 2012
Loading...

Share This Page