Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Insert a specific namespace element attribute w/out namespace attribute appears (http://www.mirthcorp.com/community/forums/showthread.php?t=215175)

jritz 11-30-2015 09:05 AM

Insert a specific namespace element attribute w/out namespace attribute appears
 
How to insert namespace specific element attribute of xsi:type to an existing XML object without a new element namespace element attribute to appear?

XML BEFORE code:
<value code="55561003" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT" displayName="Active"/>

Figure A: Current Javascript code

var entryRelationship= new XML('<entry typeCode="DRIV"><observation classCode="OBS" moodCode="EVN"><templateId root="2.16.840.1.113883.10.20.22.4.38"/><id/><code code="ASSERTION" codeSystem= "2.16.840.1.113883.5.4"><originalText></originalText></code><text/><statusCode code="completed"/><effectiveTime nullFlavor="UNK"/><value code="55561003" codeSystem= "2.16.840.1.113883.6.96" codeSystemName= "SNOMED-CT" displayName= "Active"/></observation></entry>');
var xsi= new Namespace('xsi','http://www.w3.org/2001/XMLSchema-instance');
entryRelationship.observation.value.@type= "CD";
entryRelationship.observation.value.@type.setName( 'xsi:type');

XML AFTER code:
<value code="55561003" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT" displayName="Active" xmlns:xsi="urn:hl7-org:v3" xsi:type="CD"/>

Question: After inserting the value element xsi:type attribute (eg. xsi:type="CD"), how does one code using E4X with JS to suppress the xmlns:xsi namespace specific element attribute (eg. xmlns:xsi="urn:hl7-org:v3") from the XML.

DESIRED XML:
<value code="55561003" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT" displayName="Active" xsi:type="CD"/>

bwscheller 12-01-2015 05:26 AM

Hello jritz,

The XML Namespace must be declared at some point in the XML. Typically XML Namespaces are declared on the root element so that they can be utilized at any point in the XML document as they are "inherited" down the XML tree.

Have you tried to declare the XML Namespace on the entry element? It is being attached to the value element as that is the first place that it is referenced.

jritz 12-01-2015 11:05 AM

Hi Brian.

The original XML doc contains the following root element with it's defined namespace attributes.

<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:sdtc="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

And I haven't tried to modify the XML Namespace on the entry element (eg. <value xmlns:xsi="urn:hl7-org:v3" code="55561003" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT" displayName="Active" xsi:type="CD"/>) because I believe the <value> element should be referring to the doc default XML Namespace of xmlns="urn:hl7-org:v3".

Please advise. Thanks.

jritz 12-01-2015 11:27 AM

Brian.

After re-thinking the namespace usage I noticed in my last response the xmlns:xsi namespace attribute was showing xmlns:xsi="urn:hl7-org:v3" where the correct namespace should have been what I just defined in JS (eg. var xsi= new Namespace('xsi','http://www.w3.org/2001/XMLSchema-instance'). So I moved the XML API addNamespace and setName and instead I used the setNamespace and this worked.

Fig A: Modified E4X with JS for setting the appropriate element attribute namespace to xsi

var xsi= new Namespace('xsi','http://www.w3.org/2001/XMLSchema-instance');
entryRelationship.observation.value.@type= "CD";
//entryRelationship.observation.value.@type.addNames pace(xsi); // commented out
entryRelationship.observation.value.@type.setNames pace(xsi);
//entryRelationship.observation.value.@type.setName( 'xsi:type'); // commented out


Issue resolved. Thank you for your follow-up and time. Cheers.


All times are GMT -8. The time now is 10:25 PM.

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