【问题标题】:Unable to evaluate Xpath xpression having [@xsi:type='ED'] type无法评估具有 [@xsi:type='ED'] 类型的 Xpath xpression
【发布时间】:2021-01-27 11:41:49
【问题描述】:

无法评估具有 [@xsi:type='ED'] 类型的 Xpath xpression

XPathFactory xpathFactory = XPathFactory.newInstance();

XPath xpath = xpathFactory.newXPath(); 字符串名称 = xpath.evaluate("/MCCI_IN200100UV01/PORR_IN049016UV[1]/controlActProcess[@classCode='CACT'][@moodCode='EVN']/subject[@typeCode='SUBJ'][1]/investigationEvent[@ classCode='INVSTG'][@moodCode='EVN']/component[@typeCode='COMP'][adverseEventAssessment][1]/adverseEventAssessment[@classCode='INVSTG'][@moodCode='EVN']/subject1 [@typeCode='SBJ'][1]/primaryRole[@classCode='INVSBJ']/subjectOf2[@typeCode='SBJ'][observation[id][code[@code='29'][@codeSystem= '2.16.840.1.113883.3.989.2.1.1.19']]][1]/observation[@classCode='OBS'][@moodCode='EVN']/outboundRelationship2[@typeCode='PERT'][observation/代码[@code='30'][@codeSystem='2.16.840.1.113883.3.989.2.1.1.19']][1]/观察[@classCode='OBS'][@moodCode='EVN']/值[@xsi:type='ED'][1]/text()",doc)

// doc是通过build.parse()解析的xml文档;

将 value[@xsi:type='ED'][1]/text() 更改为 value/text() 后,相同的表达式正在工作

像这样的示例 xml 内容

<outboundRelationship2 typeCode="PERT">
<observation moodCode="EVN" classCode="OBS">
<code code="30" codeSystem="2.16.840.1.113883.3.989.2.1.1.19" codeSystemVersion="2.0" /> 
<value xsi:type="ED">myalgias, back</value> 
</observation>
</outboundRelationship2>

【问题讨论】:

    标签: java xpath


    【解决方案1】:

    尝试替换

    value[@xsi:type='ED']
    

    value[@*[local-name()='type' and .='ED']]
    

    【讨论】:

    • 谢谢你的帮助,它成功了!!你有任何链接,我可以从中阅读更多相关信息。为什么没有它就不能工作?再次感谢
    • @VikashYadav 你可以阅读XML namespaces 和另一个SO ticket about this issue
    猜你喜欢
    • 1970-01-01
    • 2013-06-09
    • 2023-04-11
    • 2018-10-07
    • 2013-11-04
    • 2010-11-03
    • 1970-01-01
    • 2018-03-31
    • 2013-07-13
    相关资源
    最近更新 更多