I have a problem reading XML. I want to get a 2D array. However, when I get the data from the XML, the type of data is Unicode. Hence, I type to use list(). However, the result is not what I want. Could I use another way to get a 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]