2011-12-14 211 views
0

我有以下XML:Xpath查询以获取父元素文本及其子元素属性值?

<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' 

,但没有工作。

回答

0

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

+0

其工作........ thanx很多人....其实我即将使用pydom xpath 0.1 lib ..可以请你提供一些链接,以了解更多关于如何使用xpath查询...再thanx您的帮助..:-) – Ashishkumar 2011-12-14 13:47:08

相关问题