Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 633
KRISHNA JAYANTH Avatar asked Jun 05 '12 09:06

KRISHNA JAYANTH


People also ask

Which character is used in start with partial matching of an attribute in XPath?

In xpath, there is contains () method. It supports partial matching with the value of the attributes. This method comes as useful while dealing with elements having dynamic values in their attributes. Using ^ to target attributes starting with a particular text.

What is attribute in XPath?

Definition of XPath attribute. For finding an XPath node in an XML document, use the XPath Attribute expression location path. We can use XPath to generate attribute expressions to locate nodes in an XML document.

Which XML attribute allows us to specify XPath expressions?

xsl". The XSL file uses the XPath expressions under select attribute of various XSL tags to fetchvalues of id, firstname, lastname, nickname andsalary of each employee node.


1 Answers

To get the value of the attributes you could use:

/a/aff/@*[name()='xml:id']
like image 90
tibtof Avatar answered Sep 20 '22 12:09

tibtof