XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old June 5th, 2003, 09:03 PM
ZeroZephyr ZeroZephyr is offline
I'll set the building on fire
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 7 ZeroZephyr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old June 6th, 2003, 04:19 AM
torrent torrent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: UK
Posts: 59 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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

Reply With Quote
  #3  
Old June 6th, 2003, 04:38 PM
ZeroZephyr ZeroZephyr is offline
I'll set the building on fire
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 7 ZeroZephyr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes, but is there any application out there that will output to seperate txt files for each "node".

I hope I used "node" right.

Reply With Quote
  #4  
Old June 6th, 2003, 04:51 PM
torrent torrent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: UK
Posts: 59 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I can't think of a way but then again I'm not an expert either. Sorry.

Reply With Quote
  #5  
Old June 6th, 2003, 05:15 PM
ZeroZephyr ZeroZephyr is offline
I'll set the building on fire
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 7 ZeroZephyr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #6  
Old June 7th, 2003, 02:10 AM
torrent torrent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: UK
Posts: 59 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Cool

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Exporting XML as TXT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway