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>标签的内容。这个标签被用于所有标签。如何得到它?

4

2 回答 2

1

为此使用通用语法:

//ElementName

这将返回名为 的根元素的所有后代元素ElementName。请注意,给予/意味着child::where as//意味着descendant::

如果您想在根目录中返回后代元素,请使用以下内容:

//*
于 2012-08-02T07:27:20.850 回答
1

只需使用

//H/text()

H这将选择作为 XML 文档中任何元素的子元素的任何文本节点。

于 2012-08-02T12:52:56.767 回答