2011-12-14 138 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

相關問題