Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 如何获取具有指定文本的子节点的节点?_Xpath - Fatal编程技术网

Xpath 如何获取具有指定文本的子节点的节点?

Xpath 如何获取具有指定文本的子节点的节点?,xpath,Xpath,有一个xml: <mgns1:Champ_supplementaire> <mgns1:CODE_CS>1</mgns1:CODE_CS> <mgns1:VALEUR_CS>2</mgns1:VALEUR_CS> </mgns1:Champ_supplementaire> <mgns1:Champ_supplementaire> <mgns1:CODE_CS>2</mgns1:COD

有一个xml:

<mgns1:Champ_supplementaire>
  <mgns1:CODE_CS>1</mgns1:CODE_CS>
  <mgns1:VALEUR_CS>2</mgns1:VALEUR_CS>
</mgns1:Champ_supplementaire>
<mgns1:Champ_supplementaire>
  <mgns1:CODE_CS>2</mgns1:CODE_CS>
  <mgns1:VALEUR_CS>M</mgns1:VALEUR_CS>
</mgns1:Champ_supplementaire>
<mgns1:Champ_supplementaire>
  <mgns1:CODE_CS>3</mgns1:CODE_CS>
  <mgns1:VALEUR_CS>LOC</mgns1:VALEUR_CS>
</mgns1:Champ_supplementaire>

//node\u foo[//node\u bar=2]

如果在DOM中的任何位置有一个值为
2
node\u-foo
条,则表示选择第一个找到的
node\u-foo

//node\u foo[node\u bar=2]

表示选择第一个找到的
node\u foo
,如果它有自己的子节点
node\u bar
,值为
2

所以你需要

"//mgns1:Champ_supplementaire[mgns1:CODE_CS=2]/mgns1:VALEUR_CS"

您是如何尝试的?
NodeList nodeliste\u cs2=(NodeList)xpath.evaluate(//mgns1:Champ\u supplementaire[//mgns1:code\u CS=2]//mgns1:VALEUR\u CS”,doc,xpathctants.NODESET)
Try
“//mgns1:Champ_-supplementaire[mgns1:code_-CS=2]/mgns1:VALEUR_-CS”
我们什么时候使用
//
?简单放置,在尝试获取
NodeList-nodeliste-cs3=(NodeList)xpath时选择DOMI-get-Nullpointerexception中的任何节点。求值(//mgns1:Champ_-supplementaire[mgns1:code_-CS=3]/mgns1:VALEUR-CS”,doc,XPathConstants.NODESET)
@pheromix,我不知道您使用的是哪种工具以及它如何处理名称空间,所以请尝试相同的方法忽略名称空间
“//*[name()='Champ_supplementaire'和*[name()='code_CS'和.=2]/*[name()='VALEUR_CS'”
"//mgns1:Champ_supplementaire[mgns1:CODE_CS=2]/mgns1:VALEUR_CS"