Forum Discussion
robin
9 years agoFormer Employee
@mike.korcynski, yes there were a few small changes to make.
For the provided JSON above, this was the template that I believe produces the desired XML format (see further below):
<?xml version="1.0" encoding="UTF-8"?>
<import-record type-id="$import-record.at-type-id" type-name="$import-record.at-type-name">
   <native>
      #foreach($field in $import-record.native.field)
      <field name="$field.at-name">
         <people>
            #foreach($person in $field.people)
            <person>
               <links>
                  #foreach($link in $person.person.links)
                  <link type="$link.at-type" privacy="$link.at-privacy" href="$link.at-href" id="$link.at-id" />
                  #end
               </links>
               <last-name>$person.person.last-name</last-name>
               <initials>$person.person.initials</initials>
               <first-names>$person.person.first-names</first-names>
               <addresses>
                  #foreach($address in $person.person.addresses)
                  <address type="$address.at-type" iso-country-code="$address.at-iso-country-code">
                     #foreach($line in $address.line)
                     <line type="$line.at-type">$line.value</line>
                     #end
                     <grid href="$address.grid.at-href" longitude="$address.grid.at-longitude" latitude="$address.grid.at-latitude" id="$address.grid.at-id" />
                  </address>
                  #end
               </addresses>
               <email-address>$person.person.email-address</email-address>
               <identifiers>
                  #foreach($identifier in $person.person.identifiers)
                  <identifier scheme="$identifier.at-scheme">$identifier.value</identifier>
                  #end
               </identifiers>
            </person>
            #end
         </people>
      </field>
      #end
   </native>
</import-record>
resulting in the following output (pretty-printed):
<?xml version="1.0" encoding="UTF-8"?>
<import-record type-name="mentoring">
   <native>
      <field name="c-advisee">
         <people>
            <person>
               <last-name>Ouyang</last-name>
               <first-names>Mengyao</first-names>
            </person>
            <person>
               <last-name>Liu</last-name>
               <first-names>Jingyi</first-names>
            </person>
            <person>
               <last-name>Giannakakis</last-name>
               <first-names>Georgios</first-names>
            </person>
            <person>
               <last-name>Cao</last-name>
               <first-names>Sufeng</first-names>
            </person>
            <person>
               <last-name>Fiedler</last-name>
               <first-names>Jacob S.</first-names>
            </person>
         </people>
      </field>
   </native>
</import-record>
The $person.person usage is required because the input JSON has a people array containing objects which we assign to the $person variable in the foreach). These objects in turn contain a field person whose value is another JSON object.
mike_korcynski
9 years agoNew Contributor III
I’ve simplified my case down a bit do show here, I may file a bug as the template was generated by the Snap against a valid XSD schema, which is why I was surprised when it did not work. Thanks for the follow up.