Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/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
Java 使用XPath从xml文档中提取值的方法是什么?_Java_Xml_Xpath - Fatal编程技术网

Java 使用XPath从xml文档中提取值的方法是什么?

Java 使用XPath从xml文档中提取值的方法是什么?,java,xml,xpath,Java,Xml,Xpath,我目前正在从表单中提取数据。我能够提取rpm类型和属性,如ccoid\U键、ccoid\U版本,但我无法提取“190”。 我正在使用下面的语法“//form//rpm type/”并对其进行测试,它似乎返回了我想要的 <form xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:exforms="http://www.exforms.org/exf/1-0" xmlns:fr="http://orbeon.org/oxf/xml/

我目前正在从表单中提取数据。我能够提取rpm类型和属性,如ccoid\U键、ccoid\U版本,但我无法提取“190”。 我正在使用下面的语法“//form//rpm type/”并对其进行测试,它似乎返回了我想要的

<form xmlns:ev="http://www.w3.org/2001/xml-events"     xmlns:exforms="http://www.exforms.org/exf/1-0" xmlns:fr="http://orbeon.org/oxf/xml/form-    runner" xmlns:ns2="http://db.rpm" xmlns:ns3="http://wscommon.rpm"    xmlns:ns4="http://form.rpm" xmlns:ns5="http://form.rpm" xmlns:pipeline="java:org.orbeon.oxf.processor.pipeline.PipelineFunctionLibrary" xmlns:saxon="http://saxon.sf.net/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
<section-data>
<date>2012-06-12Z</date>
<author-name>admin admin</author-name>
<note>note</note>
</section-data>
<section-2>
<control-4>
<rpm-type ccoid_key="K000001" ccoid_version="1" type="rpm-weight">
   <rpm-value ccoid_key="K000002" type="rpm-weight-kg">190</rpm-value>
</rpm-type> 
</control-4>
<control-5>
<rpm-type ccoid_key="K000001" ccoid_version="1" type="rpm-weight">
    <rpm-value ccoid_key="K000002" type="rpm-weight-lbs">222</rpm-value>
    <rpm-value ccoid_key="K000003" type="rpm-weight-oz">21</rpm-value>
</rpm-type>
</control-5>
</section-2>
</form>

2012-06-12Z
管理员
笔记
190
222
21
我正在使用node.getNodeValue(),但我得到一个空值。。。 从日志中,我可以看出我能够提取许多属性及其值, 但是当尝试获取childNode的值时,我得到null:

2012-06-12 14:17:49028[http-thread-pool-1234(2)]调试[FormSrvcImpl:944]路径:[///form///rpm type/] 2012-06-12 14:17:49039[http-thread-pool-1234(2)]调试[FormSrvcImpl:1007]找到的节点值:null 2012-06-12 14:17:49040[http-thread-pool-1234(2)]调试[FormSrvcImpl:1054]要添加的临床单位:ClinicalUnit[idCcUnit=,idCc=0,CCOIDUNTKey=K000002,CCOIDUNTVersion=0] 2012-06-12 14:17:49041[http-thread-pool-1234(2)]调试[FormsRvCompl:1055]要添加的临床类型:ClinicalType[idCcClinicalType=,idCc=0,CCOIDCClinicalTypeKey=rpm权重,CCOIDCClinicalTypeVersion=1,valueType=null,units=null]
2012-06-12 14:17:49041[http-thread-pool-1234(2)]调试[FormSrvcImpl:1056]要添加的临床值:ClinicalValue[id_Clinical_Value=0,clinicalType=clinicalType[idCcClinicalType=,idCc=0,ccoidClinicalTypeKey=rpm权重,ccoidClinicalTypeVersion=1,valueType=null,units=null],clinicalValue=null,valueDate=null,status=ACTIVE,sourceType=ORBEON_FORM,idSource=18585,idPatient=219,clinicalUnit=null]

在我看来,您似乎在尝试对rpm类型(没有值,只有子节点)使用getNodeValue()而不是rpm value节点,该节点具有您正在查找的190个值。

根据Javadoc,如果调用某类节点,则返回null(请参阅上一链接开头的表格)。您可能应该使用

出于某种原因,我在node.getTextContent中找到了值…

实际上,我得到了childNodes,并对它们进行迭代。我可以得到属性,但不能得到值。