|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
Exporting XML as TXT
I'm sort of new to this XML stuff, so please bear with me.
I would like to find out how I can get a large XML file full of journal entries exported to seperate text files for each entries. Now, the file is set up like this: entry subject body timestamp /entry Someone mentioned to me that there was a way to do this by using Instant Saxon and an stylesheet, however as far as I can tell, the stylesheet will only tell the parser how to format and output the information in the XML. Is there any parser that will export to txt files based on a stylesheet? Or if I'm way off the mark on what I need to do, please advise. Thanks. |
|
#2
|
|||
|
|||
|
Stylesheets can indeed be instructed to transform the output to a text file. Any XSLT parser can do this.
Here are some exmaples (although you should perhaps take a tutorial on XSLT to understand them fully: http://xml.web.cern.ch/XML/www.dpaw...36.html#d172e42 |
|
#3
|
|||
|
|||
|
Yes, but is there any application out there that will output to seperate txt files for each "node".
I hope I used "node" right. |
|
#4
|
|||
|
|||
|
I can't think of a way but then again I'm not an expert either. Sorry.
|
|
#5
|
|||
|
|||
|
Alright, after a bit of trial and error, I have found the answer.
It lies in a tag that's part of the XML 1.1 recommendation: xsl:document Observe: <?xml version="1.0"?> <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:for-each select="livejournal/entry"> <xsl:variable name="filename"><xsl:value-of select="itemid"/></xsl:variable> <xsl:document method="text" href="livejournal-{$filename}.txt"> <xsl:value-of select="subject"/> <xsl:value-of select="event"/> </xsl:document> </xsl:for-each> </xsl:template> </xsl:stylesheet> Now for each node called "entry", it assigns a filename based on the "itemid" value, then proceeds to output a text file with that filename and with the formatting below it. The for-each statement loops it to it keeps creating files. This is my first experience with xml, and it looks to be a powerful scripting language in it's own right so far. I'll stick to php for intense work, but XML is definately a great tool to have! |
|
#6
|
|||
|
|||
|
Cool
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Exporting XML as TXT |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|