XPath is returning element including the tags

拥有回忆 提交于 2019-12-11 00:42:22

问题


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 <> .

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>

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 &amp; 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?

I am using the Feeds xPath parser module for Drupal (https://drupal.org/project/feeds_xpathparser).

Thank you in advance.


回答1:


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()

The expression

attribute04/category

will select the XML node instead resulting in the output of the bracings tags and the text.



来源:https://stackoverflow.com/questions/23888679/xpath-is-returning-element-including-the-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!