[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML generation from a text file

Subject: Re: XML generation from a text file
From: Frederic Laurent <fl@xxxxxxxxxxxxx>
Date: Sat, 22 Nov 2003 17:37:06 +0100
python xml generation
Hi all,

I have a plain text file as following. I want to read the text file line by line and add each line as a value of element of an xml document.

The generated xml document will be as following.

Any suggestion?

Do you like Python ? I could make it smaller but I had used the minidom package to keep a relationship with xml :)

-----------------------8<-----------------------------------
import os, sys
import xml.dom.minidom

f=file(sys.argv[1])
result = file(sys.argv[2],"w")

doc = xml.dom.minidom.Document()
root=doc.createElementNS("", "someURIs")
doc.appendChild(doc.createProcessingInstruction("xml-stylesheet",
	"type=\"text/xsl\" href=\"multiple_input3.xsl\""))
doc.appendChild(root)

# read lines from in file
for line in f.readlines():
	node = doc.createElementNS("", "file")
	node.appendChild(doc.createTextNode(line))
	root.appendChild(node)
	
# write result
result.write(doc.toprettyxml(indent="  ",encoding="ISO-8859-1"))
-----------------------8<-----------------------------------

python foo.py Folder_structure.xml Folder_structure.txt

does it...

but it's a xml centric solution, no place here for xsl...

cheers



--
XPath free testing software :  http://lantern.sourceforge.net
Frédéric Laurent                     http://www.opikanoba.org






XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.