Question
water huang · Jan 23, 2021

how to parse a xml with xmlns and xsi:type attribute

<?xml version="1.0" encoding="UTF-8"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 ../sdschemas/SDA.xsd" classCode="DOCCLIN" moodCode="EVN">
 <observation>
  <value xsi:type="ST">xxxx</value>
 </observation>
</ClinicalDocument>

this is a example XML, i don`t know how to parse it, keypoints are xmlns ,schemaLocation,xsi:type.is there a way,i could parse the xml into a object,and i can get all the data and ,i can convert the obj to a xml which is as same as the example. if anyone know somthing,please tell me,thanks!

 

00
1 0 4 160
Log in or sign up to continue

Replies

<?xml version="1.0" encoding="UTF-8"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 ../sdschemas/SDA.xsd" classCode="DOCCLIN" moodCode="EVN">
 <observation>
  <value xsi:type="ST">xxxx</value>
 </observation>
</ClinicalDocument>

You can try the ParseFile method of class %XML.TextReader. The method returns Status, but its Output parameter is a %XML.TextReader object. you can then loop over the all of the nodes of the XML document using

While (textreader.Read()) {

     ...

}

Your XML Elements will be Objects, and the Attributes of an Element will be Strings. So your ClinicalDocument objects will have Properties that will be its direct attributes, and a Property "Observation" which will be another Object. To get the Attributes you can do something like this inside your Element:

Do textreader.MoveToAttributeName("xlmns")

If textreader.LocalName = "xmlns" Set tXMLNS = textreader.Value

And so on for all attributes.

%XML.TextReader has other methods so please explore them as well...

       

thanks,%XML.TextReader could read the xml,but what i want to know is, xml 2 obj and i can reset some element`s value ,and then output the xml with new data

This use case looks good for the ISC product "HealthConnect"... it is designed to accept some data, transform it and output new data. It includes built-in XSLT Transforms that can transform CCD Documents into SDA (XML format for ISC Data Model) and back to CCD.

If you have ISC HealthConnect, you can do the following:

1) Use one of the CCDA-to-SDA transforms to create an SDA XML Document

2) Use TransformIntoObject() method of HS.Util.XSLTTransformer to get an SDA Object with Properties

3) Change whatever you need and save a new SDA Object

4) Use TransformFromObject() of the same class to get a new SDA Document

5) Use one of the SDA-to-CCDA XSLT Transforms to create a new CCDA Document.

All of this is basically out of the box... you just need to find a way to get your document into the system. If you just use FTP you can either use Ensemble FTP Service or write a script to transfer the files onto the file system where an Ensemble FileService would pick them up. 

You probably would need to create a Business Operation that would invoke the Transforms and manipulate your data; after that you can pass your output to an FTPOperation that will send the files out to your recipients.

If you don;t have HealthConnect, I would recommend getting it - XSLT is very fast compared to reading the XML directly into Objects. ISC basically solved this problem for you (for extra money of course...) If it is not possible, you may need to write your XML to Obj conversion... I don;t think there is anything like that in Ensemble...