hi
I am trying to read an xml and trying to write in excel using csv.writer. I am providing xml file name and xpath file name at command line.
But getting output like this-
(,[,',1,0,0,6,T,0, 0,0,5,6,5,4,3,0 ,',",",',2,0,1, 3,-,0,1,-,2,3,',],)
While I want it like this-
1006T000565430, 2013-01-23
Why am I getting comma after every character?
This is my code -
I am trying to read an xml and trying to write in excel using csv.writer. I am providing xml file name and xpath file name at command line.
But getting output like this-
(,[,',1,0,0,6,T,0, 0,0,5,6,5,4,3,0 ,',",",',2,0,1, 3,-,0,1,-,2,3,',],)
While I want it like this-
1006T000565430, 2013-01-23
Why am I getting comma after every character?
This is my code -
Code:
import libxml2
import fileinput
import csv
import sys
MsgFile = sys.argv[1]
XPaths = sys.argv[2]
msg = open(MsgFile, 'rt')
delim = ','
quote = '"'
values = ''
ofile = open('results_.csv', "wb")
writer = csv.writer(ofile, dialect='excel')
for line in msg:
values = '(['
doc = libxml2.parseDoc(line)
ctxt = doc.xpathNewContext()
ctxt.xpathRegisterNs("t", "http://url.abcd.com/ABCD")
xpaths = open(XPaths, 'rt')
#values += quote
for path in xpaths:
s1 = ctxt.xpathEval( path )
var = str(s1[0].content)
values += ('\'')
values += var
values += ('\'')
values += delim
values = values[:-1]
values += '])'
print values
writer.writerow(values)
values = ''
doc.freeDoc()
ctxt.xpathFreeContext()
Comment