i have a problem in reading XML. i want to get a 2D array. However, i get a problem. when i get the data from the XML. the type of data is unicode. Hence, i type to use list(). However, the result does not achieve my goal. Could i use the other way to get the 2D list? How can i remove u, \n, \t and get a correct answer. Thank you.
abc.xml
<text> <item id="1"> [ [2, 2, 1] [1, 0, 0] [1, 0, 0] ] </item> </text>
PYTHON:
import xml.dom.minidom dom = xml.dom.minidom.parse('abc.xml') bb = dom.getElementsByTagName('item') b=bb[0] l= b.firstChild.data print l a=list(l) print a
The OUTPUT:
[ [2, 2, 1] [1, 0, 0] [1, 0, 0] ] [u'\n', u' ', u' ', u' ', u' ', u'\t', u'\t', u'[', u'\n', u' ', u' ', u' ', u' ', u'\t', u'\t', u'\t', u'[', u'2', u',', u' ', u'2', u',', u' ', u'1', u']', u'\n', u' ', u' ', u' ', u' ', u'\t', u'\t', u'\t', u'[', u'1', u',', u' ', u'0', u',', u' ', u'0', u']', u' ', u'\n', u' ', u' ', u' ', u' ', u'\t', u'\t', u'\t', u'[', u'1', u',', u' ', u'0', u',', u' ', u'0', u']', u' ', u'\n', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u' ', u'\n', u' ', u' ', u' ', u' ', u'\t', u'\t', u']', u'\n', u' ', u' ', u' ', u' ', u'\t'] [Finished in 0.1s]
No comments:
Post a Comment