i get from an external service an xml structure, where html input values are grouped in a generic <custom_fields> group. when i extract the values i am not sure how to map this.
<custom_fields>
text
field1
FieldValue
</custom_fields>
<custom_fields>
checkbox
field2
Yes
</custom_fields>
When i define the mapper based on location, am i bound to the order of the fields?
How do i map the field “field2” when its in another order?
From what you’re saying, the various values inside each <custom_fields> element are not actual XML child elements, but just free form text content. There is no easy way for the datamapper to determine the order or the meaning for each of these values.
Looking at the sample you provided, a “proper” XML structure for this file should actually look like:
If the various values are not encased inside XML elements, or if we can’t rely on a fixed order, there is no way to determine whether, for instance, the word “text” is the field’s type or its value.
You could write a script and attempt to parse the <content_fields> values yourself, but you can never be certain your are interpreting those values correctly without some kind of marker inside the data file. That marker can either be implicit (i.e. a fixed order for each value) or explicit (in which case you’ll have to ask that external service to provide you with a better structure, like the one I proposed).
Maybe with other words: I want to have the :value: based on the :name: child in the group.
I need the checkbox value of “Gleich wie Rechnungsadresse”. I hope its more clear now.
Insert a Repeat step that loops on the custom_fields element:
Then inside that loop, insert an Extraction step that targets the ./name child element (you can do the same with the ./value child element):
Since you are in looping on all custom_fields elements, with each iteration the current node is successively set to each of these elements. That’s why the “./name” field is a relative reference to each of the custom_fields elements. In other words, it means “extract the name element that is a child of the currentcustom_fields element on which you are iterating”.
That way, you don’t have to specify an absolute index.
Thanks Phil, I can follow this to a degree.
There is just one point, that isnt clear yet. How Can i only get the above mentioned field value added to the current record? there is only one invoice in the xml file. at the same level as those custom fields are more detail about it like the amount and the shipping cost.