No announcement yet.

Repeating Elements in XML

  • Filter
  • Time
  • Show
Clear All
new posts

  • Repeating Elements in XML


    I am doing a mapping from an XML to CCD. I have a sample input XML in inbound template and sample CCD in outbound template. I am able to map non repeating elements but facing problem with repeating elements. For every repeating element in the input file I am unable to create a new instance in output CCD. Right now I am working on "author". I gave many tries with loops but couldn't figure out the exact logic. Can anyone please help in writing correct code? Thanks in advance.

    I am using Mirth version

    I am attaching the channel with this thread. The respective author information is present in eCrew section of my input xml. eCrew.01 is the authour id.

    Please help.

    Attached Files

  • #2
    Start with this. You will need to tweak but this should point you in the right direction. This is how in standard XML you add to a repeating outbound XML.

    PHP Code:
    for each(eCrew in msg['Header']['PatientCareReport']['eCrew']['eCrew.CrewGroup']) {

    author = <author>



    • #3
      Thank you very much for the reply. I tried your suggestion but not getting the desired output. I tried something like this

      count = msg['Header']['PatientCareReport']['eCrew']['eCrew.CrewGroup'].length();
      for(i = 0; i < count; i++)
      tmp.*::['author'][i] = new XML(tmp.*::['author']);
      tmp.*::['author'][i].*::['time']['@value'] = date;
      tmp.*::['author'][i].*::['assignedAuthor'].*::['id']['@root'] = msg['Header']['PatientCareReport']['eCrew']['eCrew.CrewGroup'][i]['eCrew.01'].toString();

      It is creating the new instance with correct mapping but it is appending at the end of the document instead of at author. I tried insertBefore(tmp.*::['custodian']) (where it should append) for appending it at right place but it is not working. Can you suggest me correct logic for appending it?


      • #4
        You did not follow his (cbarlows) suggestion at all.

        He instructed to build a CCD XML in the transformer Javascript using ECMA script. Either that way or you use the .*:: operator in the right manner. But a mix of both will not work.
        Last edited by siddharth; 04-04-2017, 10:36 PM. Reason: correction
        HL7v2.7 Certified Control Specialist!