以上回答是正確的,即:
name[0].firstChild.nodeValue
但是對我來說,像其他人一樣,我的價值進一步向下:
name[0].firstChild.firstChild.nodeValue
要找到這個我用下面的:
def scandown(elements, indent):
for el in elements:
print(" " * indent + "nodeName: " + str(el.nodeName))
print(" " * indent + "nodeValue: " + str(el.nodeValue))
print(" " * indent + "childNodes: " + str(el.childNodes))
scandown(el.childNodes, indent + 1)
scandown(doc.getElementsByTagName('text'), 0)
與Inkscape創作我的簡單的SVG文件運行此這給了我:
nodeName: text
nodeValue: None
childNodes: [<DOM Element: tspan at 0x10392c6d0>]
nodeName: tspan
nodeValue: None
childNodes: [<DOM Text node "'MY STRING'">]
nodeName: #text
nodeValue: MY STRING
childNodes:()
nodeName: text
nodeValue: None
childNodes: [<DOM Element: tspan at 0x10392c800>]
nodeName: tspan
nodeValue: None
childNodes: [<DOM Text node "'MY WORDS'">]
nodeName: #text
nodeValue: MY WORDS
childNodes:()
我使用xml.dom.minidom,在各個領域都explained on this page, MiniDom Python.
它開始看起來像大多數「迷你」問題的答案是「使用ElementTree」。 – 2012-11-27 16:16:00