16
我得到的ElementTree此错误上使用绝对路径:Python的 - 当我尝试运行下面的代码ElementTree-不能元素
SyntaxError: cannot use absolute path on element
我的XML文档看起来是这样的:
<Scripts>
<Script>
<StepList>
<Step>
<StepText>
</StepText>
<StepText>
</StepText>
</Step>
</StepList>
</Script>
</Scripts>
代码:
import xml.etree.ElementTree as ET
def search():
root = ET.parse(INPUT_FILE_PATH)
for target in root.findall("//Script"):
print target.attrib['name']
print target.findall("//StepText")
我是在Mac上的Python 2.6。我使用Xpath语法错误吗?
基本上我想显示每个脚本元素名称属性,如果它包含某个文本的StepText元素。
任何XPath表达式开始'/'或''//操作者是一个绝对的表达。除此之外,该限制(绝对表达式不允许与其他上下文节点进行比较)是特定于您的XPath引擎实现的。 – 2011-03-31 16:07:55
@ user357812有没有一种方法可以查询特定XPath实现使用的引擎? – jxramos 2017-02-22 19:27:32