Solved

XML flatten - holding parent ID


Hi I have a problem in FME desktop 2019.2 that i haven't been able to solve for a while.

I have an XML response from one server API and i need to restructure it to Post it to another server on a regular time interval. I am having trouble flattening the XML out and holding the relationship to the parent. Sounds like a common question. I can see many people asking similar questions in the forum however I cannot apply the logic to solve my problem. I assume the solution lies somewhere in the reader or flatten settings. The number of children per entry varies as you will see in the example.

In summary:

Input is an xml file. I have created an example attached.

I need to split this into 2 tables. The first is the client information. The second is the contacts. And the relationship needs to be maintained. I was hoping to use the <client> <name> as the unique key in both tables.

Output required is 2 tables or XML files.

I would really appreciate any help.

icon

Best answer by takashi 8 April 2020, 17:57

View original

5 replies

Userlevel 2
Badge +17

Hi @jrphilipp, you can read each Client feature containing its Contact elements (XML fragments) stored in a list attribute with this reader parameters setting. The list name would be xml_fragment_Contact{} in this case.

You can then keep the parent (client) ID attributes, explode the list, and flatten each Contact element to extract its attributes, as in:

Hope this helps.

Userlevel 2
Badge +17

Hi @jrphilipp, you can read each Client feature containing its Contact elements (XML fragments) stored in a list attribute with this reader parameters setting. The list name would be xml_fragment_Contact{} in this case.

You can then keep the parent (client) ID attributes, explode the list, and flatten each Contact element to extract its attributes, as in:

Hope this helps.

Alternatively you can merge Client ID attributes to Contact features using xml_id and xml_parent_id as join key. e.g.

Hi @jrphilipp, you can read each Client feature containing its Contact elements (XML fragments) stored in a list attribute with this reader parameters setting. The list name would be xml_fragment_Contact{} in this case.

You can then keep the parent (client) ID attributes, explode the list, and flatten each Contact element to extract its attributes, as in:

Hope this helps.

Thanks you takashi. I will try that. Sorry for the late reply. Appreciate the help.

Thanks you takashi. I will try that. Sorry for the late reply. Appreciate the help.

Hi Takashi

I am having trouble with the flattener parameters to extract the last component. Would you be able to point me in the right direction? I have tried to read the documentation on this transformer however without any examples i am struggling to understand the inputs.

FME flattener.fmw

Userlevel 2
Badge +17

Thanks you takashi. I will try that. Sorry for the late reply. Appreciate the help.

The XMLFlattener parameters should be:

Reply