Skip to main content
Question

merge multiple xml elements into a single attribute


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> 

2 replies

takashi
Influencer
  • 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.


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