【问题标题】:Xpath query to get the parent Element text and its child element attribute values?Xpath 查询获取父元素文本及其子元素属性值?
【发布时间】:2011-12-14 12:19:45
【问题描述】:

我有以下 XML:

<sample>
  <Message number="2">
  <Title>Program pointer has been reset</Title> 
  <Description>
  The program pointer of task 
  <arg format="%s" ordinal="3" /> 
  has been reset. 
  </Description>
  </Message>
</sample>

我正在尝试获取具有 arg 属性值的说明文本。类似"The program pointer of task %s 3 has been reset."

我的尝试看起来像

'/sample//Message[@number = $mId]/Description'

但这没有用。

【问题讨论】:

    标签: python xpath


    【解决方案1】:

    对于 XPath 2.0 或 XQuery 1.0,您可以使用 string-join(/sample//Message[@number = 2]/Description/(text() | */@*), '')。我不确定 Python 是否允许您访问 XPath 2.0 或 XQuery 1.0 库。

    【讨论】:

    • 它的工作........thanx alot man....实际上我正在使用 pydom xpath 0.1 lib..你能给我一些链接来学习更多关于如何使用 xpath 查询...再次感谢您的帮助..:-)
    猜你喜欢
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    相关资源
    最近更新 更多