web stats
XML object creation/manipulation/access - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2017, 07:48 AM
ro120908 ro120908 is offline
What's HL7?
 
Join Date: Nov 2017
Posts: 1
ro120908 is on a distinguished road
Exclamation XML object creation/manipulation/access

I am currently having trouble with an XML object within a Javascript Writer Destination. In its simplest terms I am currently trying to instantiate an XML object from a string:

var myMessage = '<Message xmlns="http://www.ncpdp.org/schema/SCRIPT" version="010" release="006"><Header><To Qualifier="C">route1</To><From Qualifier="ZZZ">route2</From><MessageID>139f333956214be8b1daf9fd9aa25949</MessageID><RelatesToMessageID>a12d9e74e3b14de7838c 660f6b3a0683</RelatesToMessageID><SentTime>2017-11-07T15:51:49.2Z</SentTime></Header><Body><Status><Code>002</Code><Description>No Messages</Description></Status></Body></Message>';

var messageXML = new XML(myMessage);

I would presume from here that I can access the xml elements with either dot notation or bracket notation. I have tried a whole slew of things to get get access to the individual elements in the way I would expect and used typeof and length to get an understanding of what the returned xml object looks like. I even attempt to use namespaces as explained at this thread here: http://www.mirthproject.org/communit...ead.php?t=8255. The actual channel Code and results are below, please help!!!!:

var responseMessage = responseMap.get("GetMsg").getMessage(); //get response message from the GetMsg destination


/* THIS IS THE RESPONSE MESSAGE FROM THE GetMsg DESTINATION
<s:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<s:Body>
<ExchangeMessageResponse xmlns="http://prescribersconnection.net">
<ExchangeMessageResult>&lt;Message xmlns="http://www.ncpdp.org/schema/SCRIPT" version="010" release="006"&gt;&lt;Header&gt;&lt;To Qualifier="C"&gt;1122443311&lt;/To&gt;&lt;From Qualifier="ZZZ"&gt;PRESCRIBERSCONNECTION&lt;/From&gt;&lt;MessageID&gt;7520da8bccd94b05b5dde91a3 47fea2e&lt;/MessageID&gt;&lt;RelatesToMessageID&gt;a12d9e74e3b 14de7838c660f6b3a0683&lt;/RelatesToMessageID&gt;&lt;SentTime&gt;2017-11-07T15:43:05.0Z&lt;/SentTime&gt;&lt;/Header&gt;&lt;Body&gt;&lt;Status&gt;&lt;Code&gt;00 2&lt;/Code&gt;&lt;Description&gt;No Messages&lt;/Description&gt;&lt;/Status&gt;&lt;/Body&gt;&lt;/Message&gt;</ExchangeMessageResult>
</ExchangeMessageResponse>
</s:Body>
</s:Envelope>
*/

var startIndex = responseMessage.indexOf("ExchangeMessageResult>");
if (startIndex != -1 ){
startIndex=startIndex + 22;
}else{
channelMap.put('destination', 'ignored');
return
}
//find first XML end tag
var endIndex = responseMessage.indexOf("</");
responseMessage = responseMessage.substring(startIndex, endIndex);
responseMessage = decodeHtml(responseMessage); //this function is created in my code template and produces the myMessage var that I am talking about at the top of this post. This is the returned string that I wish to do XML manipulations with.

channelMap.put('responseClean', responseMessage);

var messageXML = new XML(responseMessage);
var ns = 'http://www.ncpdp.org/schema/SCRIPT';

logger.info("MessageXML is: " + messageXML);
logger.info("MessageXML/Message(.) is: " + messageXML.Messsage);
logger.info("MessageXML/Message/Body(.) is: " + messageXML.Messsage.Body);
logger.info("MessageXML/Message/Body/Status(.) is: " + messageXML.Messsage.Body.Status);
logger.info("MessageXML/Message/Body/Status/Code(.) is: " + messageXML.Messsage.Body.Status.Code);

logger.info("MessageXML/Message[] is: " + messageXML['Messsage']);
logger.info("MessageXML/Message/Body[] is: " + messageXML['Messsage']['Body']);
logger.info("MessageXML/Message/Body/Status[] is: " + messageXML['Messsage']['Body']['Status']);
logger.info("MessageXML/Message/Body/Status/Code[] is: " + messageXML['Messsage']['Body']['Status']['Code']);

logger.info("Typeof MessageXML is: " + typeof(messageXML));
logger.info("Typeof MessageXML/Message(.) is: " + typeof(messageXML.Messsage));
logger.info("Typeof MessageXML/Message/Body(.) is: " + typeof(messageXML.Messsage.Body));
logger.info("Typeof MessageXML/Message/Body/Status(.) is: " + typeof(messageXML.Messsage.Body.Status));
logger.info("Typeof MessageXML/Message/Body/Status/Code(.) is: " + typeof(messageXML.Messsage.Body.Status.Code));

logger.info("Typeof MessageXML/Message[] is: " + typeof(messageXML['Messsage']));
logger.info("Typeof MessageXML/Message/Body[] is: " + typeof(messageXML['Messsage']['Body']));
logger.info("Typeof MessageXML/Message/Body/Status[] is: " + typeof(messageXML['Messsage']['Body']['Status']));
logger.info("Typeof MessageXML/Message/Body/Status/Code[] is: " + typeof(messageXML['Messsage']['Body']['Status']['Code']));

logger.info("Length of MessageXML is: " + messageXML.length());
logger.info("Length of MessageXML/Message(.) is: " + messageXML.Messsage.length());
logger.info("Length of MessageXML/Message/Body(.) is: " + messageXML.Messsage.Body.length());
logger.info("Length of MessageXML/Message/Body/Status(.) is: " + messageXML.Messsage.Body.Status.length());
logger.info("Length of MessageXML/Message/Body/Status/Code(.) is: " + messageXML.Messsage.Body.Status.Code.length());

logger.info("Length of MessageXML/Message[] is: " + messageXML['Messsage'].length());
logger.info("Length of MessageXML/Message/Body[] is: " + messageXML['Messsage']['Body'].length());
logger.info("Length of MessageXML/Message/Body/Status[] is: " + messageXML['Messsage']['Body']['Status'].length());
logger.info("Length of MessageXML/Message/Body/Status/Code[] is: " + messageXML['Messsage']['Body']['Status']['Code'].length());

logger.info("MessageXML/Message(.) w/ns is: " + messageXML.Messsage);
logger.info("MessageXML/Message/Body(.) w/ns is: " + messageXML.Messsage.ns::Body);
logger.info("MessageXML/Message/Body/Status(.) w/ns is: " + messageXML.Messsage.ns::Body.Status);
logger.info("MessageXML/Message/Body/Status/Code(.) w/ns is: " + messageXML.Messsage.ns::Body.Status.Code);

The results:
MessageXML(.) is: <Message xmlns="http://www.ncpdp.org/schema/SCRIPT" release="006" version="010"><Header><To Qualifier="C">1122443311</To><From Qualifier="ZZZ">PRESCRIBERSCONNECTION</From><MessageID>18da534fa5ae4a818089682779715644</MessageID><RelatesToMessageID>a12d9e74e3b14de7838c 660f6b3a0683</RelatesToMessageID><SentTime>2017-11-07T16:26:54.7Z</SentTime></Header><Body><Status><Code>002</Code><Description>No Messages</Description></Status></Body></Message>
MessageXML/Message(.) is:
MessageXML/Message/Body(.) is:
MessageXML/Message/Body/Status(.) is:
MessageXML/Message/Body/Status/Code(.) is:
MessageXML/Message[] is:
MessageXML/Message/Body[] is:
MessageXML/Message/Body/Status[] is:
MessageXML/Message/Body/Status/Code[] is:
Typeof MessageXML(.) is: xml
Typeof MessageXML/Message(.) is: xml
Typeof MessageXML/Message/Body(.) is: xml
Typeof MessageXML/Message/Body/Status(.) is: xml
Typeof MessageXML/Message/Body/Status/Code(.) is: xml
Typeof MessageXML[] is: xml
Typeof MessageXML/Message[] is: xml
Typeof MessageXML/Message/Body[] is: xml
Typeof MessageXML/Message/Body/Status[] is: xml
Typeof MessageXML/Message/Body/Status/Code[] is: xml
Length of MessageXML(.) is: 1
Length of MessageXML/Message(.) is: 0
Length of MessageXML/Message/Body(.) is: 0
Length of MessageXML/Message/Body/Status(.) is: 0
Length of MessageXML/Message/Body/Status/Code(.) is: 0
Length of MessageXML[] is: 1
Length of MessageXML/Message[] is: 0
Length of MessageXML/Message/Body[] is: 0
Length of MessageXML/Message/Body/Status[] is: 0
Length of MessageXML/Message/Body/Status/Code[] is: 0

MessageXML/Message(.) w/ns is:
MessageXML/Message/Body(.) w/ns is:
MessageXML/Message/Body/Status(.) w/ns is:
MessageXML/Message/Body/Status/Code(.) w/ns is:
Reply With Quote
Reply

Tags
e4x, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation