简体   繁体   中英

What is the way of extracting values from xml document using XPath?

I'm currently working on extracting data from a form. I'm able to extract the rpm-type and attributes like ccoid_key, ccoid_version but I'm unable to extract the "190". I'm using the folowing syntax '//form/ / /rpm-type/.' and tested it on http://www.xpathtester.com/test which seems to return want I want...

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

I'm using node.getNodeValue() but I get a null... From the logs, I can see I was able to extract many of the attributes and their values, but when trying to get the value of the childNode, I get null :

2012-06-12 14:17:49,028 [http-thread-pool-1234(2)] DEBUG [FormSrvcImpl:944] Path :[//form/ / /rpm-type/.] 2012-06-12 14:17:49,039 [http-thread-pool-1234(2)] DEBUG [FormSrvcImpl:1007] node value found : null 2012-06-12 14:17:49,040 [http-thread-pool-1234(2)] DEBUG [FormSrvcImpl:1054] Clinical Unit to add :ClinicalUnit [idCcUnit=, idCc=0, ccoidUnitKey=K000002, ccoidUnitVersion=0] 2012-06-12 14:17:49,041 [http-thread-pool-1234(2)] DEBUG [FormSrvcImpl:1055] Clinical Type to add :ClinicalType [idCcClinicalType=, idCc=0, ccoidClinicalTypeKey=rpm-weight, ccoidClinicalTypeVersion=1, valueType=null, units=null] 2012-06-12 14:17:49,041 [http-thread-pool-1234(2)] DEBUG [FormSrvcImpl:1056] Clinical Value to add :ClinicalValue [id_clinical_value=0, clinicalType=ClinicalType [idCcClinicalType=, idCc=0, ccoidClinicalTypeKey=rpm-weight, ccoidClinicalTypeVersion=1, valueType=null, units=null], clinicalValue=null, valueDate=null, status=ACTIVE, sourceType=ORBEON_FORM, idSource=18585, idPatient=219, clin icalUnit=null]

According to the Javadoc getNodeValue() return null if it's call on some kind of Nodes (see the table at the start of the previous link). You should probably use getTextContent() instead.

它看起来好像你试图在rpm-type(它没有值,只有一个子节点)上使用getNodeValue()而不是你正在寻找的具有190值的rpm-value节点。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM