473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple way to go from xml to simple text format

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

Jan 6 '07 #1
3 1749
* 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:bj****@hoehrmann.de · 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/
Jan 6 '07 #2

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>

Jan 6 '07 #3

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

Jan 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jacek Generowicz | last post by:
:::Title::: A simple text markup utility :::/Title::: :::Section Introduction ::: I'm looking for something to help developers wirte documentation for bits of software they are writing. The...
2
by: Mrs Howl | last post by:
I have a query that just reads one table and appends to an output table, one-for-one. No criteria. It's not a Total query (i.e. no group by). It normally run run in minutes, but gets horribly...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
8
by: Tony | last post by:
Hello I am learning C# and encountered the following problem when I tried to figure out how to print the string {0} in a Console window The following piece of codes complied OK. But when I...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
1
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
2
by: Eniac | last post by:
*argh* ... *pull hairs* I've recently started developing from ASP to ASP.NET The switch was fairly smooth since i had done some VB.net before ... then came...FORMS! :) I find it astounding...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
10
by: RickMuller | last post by:
One of my all-time favorite scripts is parseline, which is printed below def parseline(line,format): xlat = {'x':None,'s':str,'f':float,'d':int,'i':int} result = words = line.split() for i...
0
by: opedog | last post by:
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.