|
Subject: Re: [xsl] XML generation from a text file From: Frederic Laurent <fl@xxxxxxxxxxxxx> Date: Sat, 22 Nov 2003 17:37:06 +0100 |
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<------------------------------------- XPath free testing software : http://lantern.sourceforge.net Frédéric Laurent http://www.opikanoba.org
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] XML generation from a tex, Michael Kay | Thread | RE: [xsl] XML generation from a tex, SHEIKH Sajjad |
| RE: [xsl] XLST 2, Karthikeyan Ramnath | Date | [xsl] The output of one template is, Dongling Ding |
| Month |