No announcement yet.

Insert a specific namespace element attribute w/out namespace attribute appears

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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."/><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','');
    [email protected]= "CD";
    [email protected]( '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.

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

  • #2
    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.
    Brian Scheller
    Mirth Fundamentals Certified 06/15
    Mirth Advanced Certified 10/15


    • #3
      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="">

      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.


      • #4

        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',''). 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','');
        [email protected]= "CD";
        //[email protected] pace(xsi); // commented out
        [email protected] pace(xsi);
        //[email protected]( 'xsi:type'); // commented out

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