Skip to main content
Question

merge multiple xml elements into a single attribute

  • May 8, 2018
  • 2 replies
  • 289 views

Forum|alt.badge.img

I have an attribute of a feature called RTN_NOTES. It contains free text stored in an xml structure as below.

I need to merge the values of the <Run> element entries in to a single output text attribute(varchar). I have tried to use the XMLFlattener feature, but this seems to only return the contents of the 1st <Run> entry.  Any help would be appreciated. Thanks, Michael (FME Newbie)

<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph>
<Run FontWeight="Normal" xml:space="preserve">I visited Joe Bloggs to discuss how he feels things are going.</Run>
</Paragraph>
<Paragraph>
<Run FontWeight="Normal" xml:space="preserve">Joe is worried about his situation.</Run>
</Paragraph>
<Paragraph>
<Run FontWeight="Normal" xml:space="preserve">I have suggested a follow up meeting.</Run>
</Paragraph>
</Section> 

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.

2 replies

takashi
Celebrity
  • May 8, 2018

Hi @michaelpralph, if you set "Section" to the Elements to Match parameter in the XMLFlattener, it creates a list attribute called "Paragraph{}.Run", which stores values of all <Run> elements. You can then concatenate its elements with the ListConcatenator. Note: If there could be a case where there is just a single <Paragraph> element, additional consideration would be necessary.

0684Q00000ArJwoQAF.png

Alternatively, you can also use the XMLXQueryExtractor with this XQuery Expression. This works regardless of the number of <Paragraph> elements.

XQuery Expression:

declare default element namespace "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
//Paragraph/Run/text()

0684Q00000ArJpyQAF.png


Forum|alt.badge.img

Many thanks @takashi, I applied the XQuery expression and it works perfectly producing a neat block of free text form the multiple Run elements.

Once again, many thanks.