Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath: select node based in a condition (with local-name())

Tags:

xml

xpath

The question is quite silly, but I am completely stuck. I want to extract child nodes of a node based on a condition. The XML is as follows:

<a>   <aCode>aaa</aCode>  <aValue>bbb</aValue> </a> 

The expression is obvious: //a[aCode='aaa']

But I can't get how I should change it if it is with namespaces and I've got to use local-name(). I've tested the following and it gives a parsing error:

/*[local-name()='a'][[local-name()='aCode']='aaa'] 

Has anyone any idea of what I should do?

like image 268
gisly Avatar asked May 30 '12 09:05

gisly


People also ask

What is local name () in XPath?

The local-name function returns a string representing the local name of the first node in a given node-set.


1 Answers

You probably meant

//*[local-name()='a'][*[local-name()='aCode']='aaa'] 
like image 76
choroba Avatar answered Sep 19 '22 18:09

choroba