Dealing with repeating XML fields


(Rcoundon) #1

Hi

I have XML in the following format:

<appointments>
  <appointment>
    <Field name="Route Date">2018-10-10</Field>
    <Field name="Route ID">2296</Field>
    <Field name="Activity ID">1234</Field>
    <Field name="Master Activity ID" />
    <Field name="property_131" />
    <Field name="property_134" />
   </appointment>
   <appointment>
     <Field name="Route Date">2018-10-10</Field>
     <Field name="Route ID">2796</Field>
     <Field name="Activity ID">7233</Field>
     <Field name="Master Activity ID" />
     <Field name="property_131" />
     <Field name="property_134" />
    </appointment>
   </appointments>

I'd like to be able to do a few things with this:

Ignore the elements where name="property*"
Take the data from the element and the value from the name attribute to create an output that looks like:

    {
        "Route Date": "2018-10-10",
        "Route ID": "2296",
        "Activity ID": "1234",
    },
    {
        "Route Date": "2018-10-10",
        "Route ID": "2796",
        "Activity ID": "7233",
    }

I've managed to pull out the attribute name using the following xpath in the xml filter:
/appointments/appointment/Field[not(starts-with(@name, 'property'))]/text()", "field"
but I can't get my head around dealing with building the JSON that I need. Can anyone provide any pointers?
Cheers


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.