2

我正在使用 xPath 读取 XML 文件,但是当尝试获取某个元素的内容时,它会返回它,包括标签 <> 。

XML 文件的结构如下:

<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 来获取类别元素。但是,这就是我要回来的:

xpathparser:04 :
<Category>Bed &amp; Breakfast and Inns</Category>
xpathparser:04 :
<Category>Hotel</Category>
...etc...

它返回包括标签在内的整个元素。有人知道这里出了什么问题吗?

我正在为 Drupal ( https://drupal.org/project/feeds_xpathparser ) 使用 Feeds xPath 解析器模块。

先感谢您。

4

1 回答 1

2

为了在 XPath 表达式中选择节点的文本部分,您必须使用text()如下函数:

attribute04/category/text()

表达方式

attribute04/category

将选择 XML 节点,而不是导致大括号标签和文本的输出。

于 2014-05-27T13:53:37.407 回答