1

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>
Vikash Yadav
  • 35
  • 1
  • 3

1 Answers1

-1

Try to replace

value[@xsi:type='ED']

with

value[@*[local-name()='type' and .='ED']]
JaSON
  • 4,843
  • 2
  • 8
  • 15
  • Thankyou for help,It worked!! Do you have any link from where I can read more about this. And why it was not working without it? Thanks again – Vikash Yadav Oct 13 '20 at 09:53
  • @VikashYadav you can read about [XML namespaces](https://www.w3schools.com/xml/xml_namespaces.asp) and another [SO ticket about this issue](https://stackoverflow.com/questions/5239685/xml-namespace-breaking-my-xpath) – JaSON Oct 13 '20 at 10:15