英文:
Unable to evaluate Xpath xpression having [@xsi:type='ED'] type
问题
无法评估具有 [@xsi:type='ED'] 类型的 XPath 表达式
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
String name = 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[@code='30'][@codeSystem='2.16.840.1.113883.3.989.2.1.1.19']][1]/observation[@classCode='OBS'][@moodCode='EVN']/value[@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">肌痛,背部</value>
</observation>
</outboundRelationship2>
英文:
Unable to evaluate Xpath xpression having [@xsi:type='ED'] type
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
String name = 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[@code='30'][@codeSystem='2.16.840.1.113883.3.989.2.1.1.19']][1]/observation[@classCode='OBS'][@moodCode='EVN']/value[@xsi:type='ED'][1]/text()",doc)
// doc is xml document parsed through build.parse();
Same expression is working after changing value[@xsi:type='ED'][1]/text() to value/text()
Sample xml content like this
<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>
答案1
得分: -1
尝试将
value[@xsi:type='ED']
替换为
value[@*[local-name()='type' and .='ED']]
英文:
Try to replace
value[@xsi:type='ED']
with
value[@*[local-name()='type' and .='ED']]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论