gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:45:01 25 4
gpt4 key购买 nike

我目前正在研究从表单中提取数据。我能够提取 rpm 类型和属性,例如 ccoid_key、c​​coid_version,但无法提取“190”。我使用以下语法“//form///rpm-type/”。并在 http://www.xpathtester.com/test 上进行了测试这似乎返回想要我想要...

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

我正在使用 node.getNodeValue() 但我得到一个 null...从日志中,我可以看到我能够提取许多属性及其值,但是当尝试获取 childNode 的值时,我得到 null :

2012-06-12 14:17:49,028 [http-thread-pool-1234(2)] 调试 [FormSrvcImpl:944] 路径:[//form///rpm-type/.]2012-06-12 14:17:49,039 [http-thread-pool-1234(2)] DEBUG [FormSrvcImpl:1007] 找到节点值:null2012-06-12 14:17:49,040 [http-thread-pool-1234(2)] 调试 [FormSrvcImpl:1054] 临床单位添加:ClinicalUnit [idCcUnit=, idCc=0, ccoidUnitKey=K000002, ccoidUnitVersion=0]2012-06-12 14:17:49,041 [http-thread-pool-1234(2)] 调试 [FormSrvcImpl:1055] 要添加的临床类型: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)] 调试 [FormSrvcImpl:1056] 临床值(value)添加: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、clinicalUnit=null]

最佳答案

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

关于java - 使用 XPath 从 xml 文档中提取值的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11000328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com