我尝试用XPath、Python和etree来提取一个值。我对收到的.xml文件没有任何影响,我认为它似乎是无效的。
我的方法已经提取了我想要检查的文本节点对象。
# This is the tag.
textTag = lastExportTree.xpath("//TEXT_NODE[@PROPERTY = '%s']/TEXT[@ID = '%s']" % (key, id[1]))
# This is a part of the xml. I already have the text node I want to examine.
&
我正在解析位于以下链接的XML:
我需要访问节点内部的数据,我编写的程序似乎告诉我,节点内部什么都没有。这是我的代码:
import urllib
import xml.etree.ElementTree as ET
#prompt for link where xml data resides
#Use this link for testing: http://python-data.dr-chuck.net/comments_42.xml
url = raw_input('Enter URL Link: ')
#open url and prep for pars
我对ElementTree.iter()有一个问题。
所以我在这个链接中尝试了这个例子:
下面是我尝试过的方法:
import elementtree.ElementTree as ET
tree = ET.parse('XML_file.xml')
root = tree.getroot()
for elem in tree.iter():
print elem.tag, elem.attrib
我得到了这个错误AttributeError: ElementTree实例没有属性'iter‘
附加信息:我的Python版本是2.4,我单独安装了elementtr