2012-08-02 48 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::

如果你喜欢根内返回子孙元素,然后使用类似:

//*