Announcement

Collapse
No announcement yet.

Custom XML Namespaces

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom XML Namespaces

    Hey,

    Here in Belgium we have an organisation that expects us to send them xml files in following format:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <HC_PEMR_Message xmlns="http://www.healthconnect.be/bindings" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="ttp://www.w3.org/2001/XMLSchema-instance">
      <Version>1</Version>
      <MsgHeader>
        <MsgDateTime></MsgDateTime>
        <MsgID></MsgID>
        <Action></Action>
      </MsgHeader>
      <MsgBody>
        <From>
          <NIHII></NIHII>
          <Person>
            <Name></Name>
            <FirstName></FirstName>
          </Person>
          <CompanyName></CompanyName>
        </From>
        <Patient>
          <PatientID></PatientID>
          <INSS></INSS>
          <Name></Name>
          <FirstName></FirstName>
          <DateOfBirth></DateOfBirth>
          <Sex></Sex>
          <Address>
            <Street></Street>
            <ZipCode>5</ZipCode>
            <City></City>
            <Country></Country>
          </Address>
        </Patient>
        <Direction></Direction>
        <ActionDateTime></ActionDateTime>
        <Subject></Subject>
        <RIS>
          <Requestor>
            <NIHII></NIHII>
            <Person>
              <Name></Name>
              <FirstName></FirstName>
            </Person>
            <CompanyName></CompanyName>
          </Requestor>
          <Addressees></Addressees>
          <Summary></Summary>
          <Link></Link>
          <Protocol></Protocol>
        </RIS>
      </MsgBody>
    </HC_PEMR_Message><HC_PEMR_Message>
      <Version>1</Version>
      <MsgHeader>
        <MsgDateTime></MsgDateTime>
        <MsgID></MsgID>
        <Action></Action>
      </MsgHeader>
      <MsgBody>
        <From>
          <NIHII></NIHII>
          <Person>
            <Name></Name>
            <FirstName></FirstName>
          </Person>
          <CompanyName></CompanyName>
        </From>
        <Patient>
          <PatientID></PatientID>
          <INSS></INSS>
          <Name></Name>
          <FirstName></FirstName>
          <DateOfBirth></DateOfBirth>
          <Sex></Sex>
          <Address>
            <Street></Street>
            <ZipCode>5</ZipCode>
            <City></City>
            <Country></Country>
          </Address>
        </Patient>
        <Direction></Direction>
        <ActionDateTime></ActionDateTime>
        <Subject></Subject>
        <RIS>
          <Requestor>
            <NIHII></NIHII>
            <Person>
              <Name></Name>
              <FirstName></FirstName>
            </Person>
            <CompanyName></CompanyName>
          </Requestor>
          <Addressees></Addressees>
          <Summary></Summary>
          <Link></Link>
          <Protocol></Protocol>
        </RIS>
      </MsgBody>
    </HC_PEMR_Message>
    Somehow me and my college dont succeed in adding the namespaces like shown above. if we add namespaces with new default namespace we get the following xmlns:e4x_0="http://www.healthconnect.be/bindings"

    Is there any way to get the wanted result ?
    we tried:
    • Adding the namespaces in the template and uncheck remove namespaces
    • Adding them with javascript
    • Building the XML with javascript and not using a template


    I thank you in advance for your time and effort.

    Best regards,
    Thomas

  • #2
    Set that XML message as your outbound template, then do this in a JavaScript step:

    Code:
    tmp.setNamespace(new Namespace('', 'http://www.healthconnect.be/bindings'));
    tmp.addNamespace(new Namespace('xsd', 'http://www.w3.org/2001/XMLSchema'));
    tmp.addNamespace(new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance'));
    Also FYI, it looks like the sample XML message you posted has a typo. The namespace bound to xsi uses "ttp://www.w3.org/2001/XMLSchema-instance" rather than "http://www.w3.org/2001/XMLSchema-instance".
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


    - How do I foo?
    - You just bar.

    Comment


    • #3
      Hey,

      thanks for the fast reply! It's working for this tag indeed, but now I see that the child nodes are getting an empty namespace like this:

      <Version xmlns="">
      <MsgHeader xmlns="">
      <MsgBody xmlns="">

      Is this normal behaviour & will this affect further handling of the XML?

      Thanks in advance.

      KR,
      Thomas

      Comment


      • #4
        That is not happening for me; there's probably an additional error in your code.
        Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

        Nicholas Rupley
        Work: 949-237-6069
        Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


        - How do I foo?
        - You just bar.

        Comment


        • #5
          I checked the config and tried on two different java versions.
          The result is the same.

          Please find attached the Channel i used to experiment with it.
          the result is :

          Code:
          <HC_PEMR_Message xmlns="http://www.healthconnect.be/bindings" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <Version xmlns="">1</Version>
              <MsgHeader xmlns="">
                  <MsgDateTime/>
                  <MsgID/>
                  <Action/>
              </MsgHeader>
              <MsgBody xmlns="">
                  <From>
                      <NIHII/>
                      <Person>
                          <Name/>
                          <FirstName/>
                      </Person>
                      <CompanyName/>
                  </From>
                  <Patient>
                      <PatientID/>
                      <INSS/>
                      <Name/>
                      <FirstName/>
                      <DateOfBirth/>
                      <Sex/>
                      <Address>
                          <Street/>
                          <ZipCode>5</ZipCode>
                          <City/>
                          <Country/>
                      </Address>
                  </Patient>
                  <Direction/>
                  <ActionDateTime/>
                  <Subject/>
                  <RIS>
                      <Requestor>
                          <NIHII/>
                          <Person>
                              <Name/>
                              <FirstName/>
                          </Person>
                          <CompanyName/>
                      </Requestor>
                      <Addressees/>
                      <Summary/>
                      <Link/>
                      <Protocol/>
                  </RIS>
              </MsgBody>
          </HC_PEMR_Message>
          If you could check what i'm doing wrong, that would be wonderfull!!!!


          BR,
          Thomas
          Attached Files

          Comment


          • #6
            I used the same exact channel in 3.0.3 and it works fine. No extra xmlns attributes.
            Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

            Nicholas Rupley
            Work: 949-237-6069
            Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


            - How do I foo?
            - You just bar.

            Comment


            • #7
              strange, we get a different output.
              Could it depend on the java version we are using? or has this nothing to do with this ?

              version used: 3.0.3.7171
              Java version: 1.7.0_60

              thx for your reply's so far!

              Comment


              • #8
                I am facing same issue of empty xmlns attribute getting appended to each child
                Mirth 3.1.1, Windows 7/Ubuntu 14.04, Oracle JDK 7
                Any resolution?

                I am trying to convert json to NCPDP eRx XML.
                For a temporary workaround I haven't added any namespace in root tag of XML and then replaced root tag with namespace in destination transformer.
                Last edited by jayant.singh; 09-04-2015, 09:59 PM.

                Comment


                • #9
                  Json to xml

                  What do you use to Convert Json in XML or NCPDP??

                  Comment


                  • #10
                    Xmlns namespace trouble

                    Hi guys,

                    I went through this thread and I experienced the same problem as stated above. In the child nodes im getitng additional <xmlns=""> attributes. Is there a way to omit this?.. I'm using the mirth version 3.3.0.7801 can you guys help me with this?

                    Mirth Interface Engineer
                    AWS DevOps

                    Comment


                    • #11
                      Empty xmlns bug hack

                      Just letting anyone else who visits this page know how I fixed the empty xmlns problem. Warning: it's rather hacky.

                      Code:
                      var xmlAsString = tmp.toString();
                      xmlAsString = xmlAsString.split('xmlns=""').join('');
                      tmp = new XML(xmlAsString);
                      Essentially, I have the "Strip Namespaces" XML feature turned on, apply all the various transformations I need without having to worry about namespaces, and then have a final JavaScript step where I use the setNamespace method to add the default namespace to the root element (which has the side effect of adding a number of blank namespaces to child elements), and then do the above to fix child element namespaces.

                      Comment


                      • #12
                        Hi guys,
                        I don't know if this is still an issue, but I was experiencing the same problem and here is the workaround I did:


                        Code:
                        tmp.setNamespace(new Namespace('', 'http://www.w3.org/2001/XMLSchema'));
                        tmp.addNamespace(new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema'));
                        tmp = new XML(tmp.toString().replace(/xmlns=""/g, ''));

                        Comment

                        Working...
                        X