Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
在Java中使用XPath解析XML-在Java中使用XPath和NodeList从XML文件中获取数据_Java_Xml_Xpath_Nodelist - Fatal编程技术网

在Java中使用XPath解析XML-在Java中使用XPath和NodeList从XML文件中获取数据

在Java中使用XPath解析XML-在Java中使用XPath和NodeList从XML文件中获取数据,java,xml,xpath,nodelist,Java,Xml,Xpath,Nodelist,我有这个xml文件,我想用Xpath获取一些值 工作完成了一半,但在文件的最后部分(状态节点)遇到了一些问题 第二个例子 wf2000 wf2 description 2 3 text text text text text text text 3 description1 description1 description1 查看ID为2的状态,文本是description2而不是description1。 我认为解析器不会移动到第二个子级,它总是在第一个子级。 因此,我该怎么做,也该怎么做才

我有这个xml文件,我想用Xpath获取一些值

工作完成了一半,但在文件的最后部分(状态节点)遇到了一些问题

第二个例子

wf2000 wf2 description 2 3 text text text text text text text
3
description1
description1
description1
查看ID为2的状态,文本是
description2
而不是
description1
。 我认为解析器不会移动到第二个子级,它总是在第一个子级。
因此,我该怎么做,也该怎么做才能获得state?????

的属性,您必须执行以下操作:

for (int k = 0; k < States.getLength(); k++) {
          String desc_state = xPath.evaluate("states/state[position()=" + (k + 1) + "]", workflow);
          String id_employee = xPath.evaluate("states/state[position()=" + (k + 1) + "]/@IDemployee", workflow);
          System.out.println(desc_state + ":" + id_employee); 
}
for(int k=0;k
感谢您的快速回复以及如何处理属性???@nabeelmukhtar:我在java中使用xpath进行xml签名,但xpath转换不起作用。请查看此链接-您不应该迭代状态节点列表吗?!关于这个问题,我得到了一个很好的答案
wf1000 wf1 description 1 2 text text text text text text text
2
description1
description1
wf2000 wf2 description 2 3 text text text text text text text
3
description1
description1
description1
for (int k = 0; k < States.getLength(); k++) {
          String desc_state = xPath.evaluate("states/state[position()=" + (k + 1) + "]", workflow);
          String id_employee = xPath.evaluate("states/state[position()=" + (k + 1) + "]/@IDemployee", workflow);
          System.out.println(desc_state + ":" + id_employee); 
}