开发者

Selecting specific node using XPATH

开发者 https://www.devze.com 2023-02-05 05:22 出处:网络
I have simple XML document: <?xml version=\"1.0\" e开发者_如何转开发ncoding=\"utf-8\" ?>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消