Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Simple way to go from xml to simple text format

Reply
Thread Tools

Simple way to go from xml to simple text format

 
 
mathieu
Guest
Posts: n/a
 
      01-06-2007
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

 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      01-06-2007
* 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 · (E-Mail Removed) · 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/
 
Reply With Quote
 
 
 
 
mathieu
Guest
Posts: n/a
 
      01-06-2007

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"
xmlnssl="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>

 
Reply With Quote
 
mathieu
Guest
Posts: n/a
 
      01-06-2007

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want help on how we convert output to tabular format Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format. sharan XML 1 10-26-2007 01:20 PM
Open Document Format / Rich Text Format Editor in Java Dominik Java 4 03-22-2007 01:55 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM
Best Way to "Format" Plain Text for Email Edge Computer Information 0 02-03-2004 07:54 PM



Advertisments