class %XML.XPATH.Document / parsing CDA xml document Help please

423 views
Skip to first unread message

brad...@gmail.com

unread,
Jan 9, 2014, 4:46:51 PM1/9/14
to intersystems...@googlegroups.com
I am currently writing a test program where I need to parse a CDA document but the class i am using " %XML.XPATH.Document" doesn't seem to be parsing it correctly.  Below is the syntax I am using which is straight from the example methods in the class, and the "cdaTemp.xml" document is attached.

set pFile = "c:\cdaTemp.xml"
set tSC = ##class(%XML.XPATH.Document).CreateFromFile(pFile,.xmlobj)
Set tSC=xmlobj.EvaluateExpression("/ClinicalDocument", "count(templateId)", .tResults)
do ##class(%XML.XPATH.Document).ExampleDisplayResults(tResults)

OUTPUT is blank, nothing

If I use the other file I attached "testXml.xml" with the same code above I get the following output below in red:

XPATH VALUE
3


The only difference is the amount of content in the "cdaTemp.xml" file versus the "testXml.xml" file but the nodes I am trying to count are the same.

Thanks in advance for any help here.

Brad

cdaTemp.xml
testXml.xml

Sean

unread,
Jan 9, 2014, 8:49:01 PM1/9/14
to intersystems...@googlegroups.com, brad...@gmail.com
It has to do with the namespace.  In your test file, you don’t have one.  In the CCD, there is one.

CCD
<ClinicalDocument xmlns="urn:hl7-org:v3">

Test
<ClinicalDocument>

In order for the expression to match properly, you have to define a prefix mapping and use the prefix in your expression.
http://docs.intersystems.com/ens20121/csp/docbook/DocBook.UI.Page.cls?KEY=GXML_xpath#GXML_xpath_prefix_mappings

Set xmlobj.PrefixMappings="h urn:hl7-org:v3"
Set tSC=xmlobj.EvaluateExpression("/h:ClinicalDocument", "count(h:templateId)", .tResults)
do ##class(%XML.XPATH.Document).ExampleDisplayResults(tResults)           
XPATH VALUE
2



Paul Riker

unread,
Oct 14, 2016, 12:27:04 AM10/14/16
to Caché, Ensemble, DeepSee, brad...@gmail.com, srph...@gmail.com
What if you have multiple sources with different name spaces?
<ClinicalDocument xmlns:voc="urn:hl7-org:v3/voc" xmlns:sdtc="urn:hl7-org:sdtc" xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:cda="urn:hl7-org:v3" xmlns:sdtc="urn:hl7-org:sdtc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 CDA.xsd">
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Paul Riker

unread,
Oct 14, 2016, 9:17:35 AM10/14/16
to Caché, Ensemble, DeepSee, brad...@gmail.com, srph...@gmail.com
Set tSC=##class(%XML.XPATH.Document).CreateFromFile("/hs/test1.xml",.tDoc)
Set tDoc.PrefixMappings=##class(HS.IHE.Util).XPathNamespaces()
Set tSC=tDoc.EvaluateExpression("/hl7:ClinicalDocument","count(hl7:templateId",.tRes)
Do ##class(%XML.XPATH.Document).ExampleDisplayResults(tRes)
Reply all
Reply to author
Forward
0 new messages