2012-08-02 33 views
1

我有一個標籤<H>some data</H>。這個標籤可以來自XML文件中的任何地方。下面是一個例子 -在可以任意位置的節點內搜索數據

<Name>This is some data. It is an <H>highlighted text</H></Name> 
    <DDesc>Here is the Detailed <H>Description</H> 
    <Features>Following are the important <H>features of</H> the product</Features> 
     <Construction>Some text <H>goes here</H></Construction> 
     <Design>Some design <H>stuff</H> information</Design> 
    </Features> 
    </DDesc> 
</Name> 

現在我想要得到<H>..</H>標籤的內容。這個標籤正在所有標籤中使用。 如何得到它?

+0

你想要一個字符串作爲結果還是一個字符串集合,每個h元素一個字符串? – 2012-08-02 13:28:33

回答

1

只需使用

//H/text() 

這裏選擇任何H元素的子任何文本節點在XML文檔中。

1

使用一般的語法爲:

//ElementName 

這將返回命名爲ElementName根元素的所有後代元素。請注意,/表示child::,其中//表示descendant::

如果你喜歡根內返回子孫元素,然後使用類似:

//*