Skip to main content
Solved

XML flatten - holding parent ID

  • April 8, 2020
  • 5 replies
  • 72 views

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.

Best answer by takashi

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

takashi
Celebrity
  • Best Answer
  • April 8, 2020

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.


takashi
Celebrity
  • April 8, 2020

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.


  • Author
  • April 14, 2020

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.


  • Author
  • April 14, 2020

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


takashi
Celebrity
  • April 14, 2020

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

The XMLFlattener parameters should be: