Re: [xsl] XML generation from a text file

Subject: Re: [xsl] XML generation from a text file
From: Frederic Laurent <fl@xxxxxxxxxxxxx>
Date: Sat, 22 Nov 2003 17:37:06 +0100
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