Selecting specific node using XPATH
I have simple XML document:
<?xml version="1.0" e开发者_如何转开发ncoding="utf-8" ?>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<date>BBB</date>
<name>CCC</name>
</root>
I need to select name value "CCC", by date value "BBB".It works fine for next XPATH:
/root[date=BBB]/name
But as long as i have namespace declared i can not upper XPATH. For this case i know it is possible to use local-name() function. But if i write next expression
/*[local-name() = 'root[date=BBB]']/*/*[local-name() = 'name']
It does not work.
Replacing any QName test for *[local-name()='...']
in
/root[date='BBB']/name
You should use:
/*[local-name() = 'root'][*[local-name()='date']='BBB']
/*[local-name() = 'name']
But for this case I would use:
/*[*[local-name()='date']='BBB']/*[local-name() = 'name']
A little shorter with a "whatever root element".
精彩评论