Skip to main content
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.

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.

View original
Did this help you find an answer to your question?

5 replies

takashi
Influencer
  • 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
Influencer
  • April 8, 2020
takashi wrote:

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
takashi wrote:

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
jrphilipp wrote:

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
Influencer
  • April 14, 2020
jrphilipp wrote:

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

The XMLFlattener parameters should be:


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings