XPath 正在返回包含标签的元素 [英] XPath is returning element including the tags
问题描述
我正在使用 xPath 读取 XML 文件,但是当尝试获取某个元素的内容时,它返回的内容包括标签 <> .
I am using xPath to read an XML file, but when trying to get the contents of a certain element, it returns it including the tags <> .
XML 文件的结构如下:
The XML file is structured like this:
<item>
<attribute01>something</attribute01>
<attribute02>something</attribute02>
<attribute03>something</attribute03>
<attribute04>
<category>Some category name</category>
<category>Some other category name</category>
</attribute04>
</item>
我在//item 的上下文中工作,然后使用 attribute04//category 来获取类别元素.但是,这就是我要回来的:
I am working in the context of //item and then using attribute04//category to get the category element. However, this is what I'm getting back:
xpathparser:04 :
<Category>Bed & Breakfast and Inns</Category>
xpathparser:04 :
<Category>Hotel</Category>
...etc...
它返回包括标签在内的整个元素.有人知道这里出了什么问题吗?
It returns the entire element including the tags. Does anybody have an idea what is going wrong here?
我正在将 Feeds xPath 解析器模块用于 Drupal (https://drupal.org/project/feeds_xpathparser).
I am using the Feeds xPath parser module for Drupal (https://drupal.org/project/feeds_xpathparser).
提前致谢.
推荐答案
为了在 XPath 表达式中选择节点的文本部分,您必须使用 text()
函数,如下所示:
In order to select the text portion of a node in an XPath expression you have to use the text()
function as follows:
attribute04/category/text()
表达式
attribute04/category
将选择 XML 节点,而不是产生支撑标记和文本的输出.
will select the XML node instead resulting in the output of the bracings tags and the text.
这篇关于XPath 正在返回包含标签的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!