How to retrieve value of an attribute which contains colon in the attribute name using xpath

邮差的信 提交于 2019-12-21 07:57:28

问题


I have a simple requirement where in I need to fetch the value of attribute xml:id i.e af1. I am making use of a SAXParser and here is my xpath:a/aff/@xml:id on the contrary I was able to fetch value of using the xpath:a/aff/@value.

But i was unable to retrieve the value could you please help me?

<?xml version="1.0" encoding="UTF-8" ?>
<a>
   <aff xml:id="af1" value="a">
        <uAff>
            Hello
        </uAff>
    </aff>
    <aff xml:id="corr1">
        <uAff>
            Hello1
        </uAff>
    </aff>
</a>

Thanks in advance.


回答1:


To get the value of the attributes you could use:

/a/aff/@*[name()='xml:id']



回答2:


/a/aff/@xml:id works just fine in getting the values...

Are you trying to get both values?

If you are trying to get just the first value you could use /a/aff[1]/@xml:id



来源:https://stackoverflow.com/questions/10894696/how-to-retrieve-value-of-an-attribute-which-contains-colon-in-the-attribute-name

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