Skip to main content
Question

Extract values from dynamically changing XML list elements & sub-elements


mmccart
Supporter
Forum|alt.badge.img+17

I have a real-time XML feed that I am consuming that identifies road conditions. The issue is that the provider has changed the XML feed and grouped multiple segments with the same road condition into a single message. This message can grow and and shrink at any time. It can also add additional sub-elements to further describe the condition. In the past we were able to use an xfMap and expose the XML elements that way. This year, it has become more complicated. They've added sub-elements but FME is not resetting the list index to 0 for the sub-elements. Here are some examples:

Example with Single Route & Multiple Conditions:

Example with Multiple Routes & Single Condition:

Example with Multiple Routes & Multiple Conditions:

I've tried to leverage the XMLFragmenter, ListExploder, ListIndexer and no luck.

The ultimate goal is to have a single record for each road segment with all the corresponding road condition attributes, message information, etc.

Here are the full screenshots from Data Inspector for the above examples so you can see all the data for the specific road condition message:

Here's the XML Feed example (access to live feed is restricted):

Thanks in advance.

-Mark

2 replies

takashi
Influencer
  • October 8, 2018

Hi @mmccart, if you need to save values of "description/phrase/dnu-cars-segment-ia" elements and values of "description/additional-text/description" elements into different two list attributes,  a possible way is to use the XMLXQueryExtractor like this. Assuming that you have fragmented the XML document into individual "full-event-update" element with the XMLFragmenter.

XQuery Expression:

fme:set-list-attribute('_condition{}', {
    for $x in //description/phrase/dnu-cars-segment-ia
    return data($x)
}),
fme:set-list-attribute('_route{}', {
    for $x in //description/additional-text/description
    return data($x)
})

0684Q00000ArLfQQAV.png

In addition, you can configure the XMLFragmetner not to flatten those elements via the Ignore Specific Sub-Element parameter in the XML Flatten Options.

0684Q00000ArLkuQAF.png


mmccart
Supporter
Forum|alt.badge.img+17
  • Author
  • Supporter
  • October 8, 2018
takashi wrote:

Hi @mmccart, if you need to save values of "description/phrase/dnu-cars-segment-ia" elements and values of "description/additional-text/description" elements into different two list attributes,  a possible way is to use the XMLXQueryExtractor like this. Assuming that you have fragmented the XML document into individual "full-event-update" element with the XMLFragmenter.

XQuery Expression:

fme:set-list-attribute('_condition{}', {
    for $x in //description/phrase/dnu-cars-segment-ia
    return data($x)
}),
fme:set-list-attribute('_route{}', {
    for $x in //description/additional-text/description
    return data($x)
})

0684Q00000ArLfQQAV.png

In addition, you can configure the XMLFragmetner not to flatten those elements via the Ignore Specific Sub-Element parameter in the XML Flatten Options.

0684Q00000ArLkuQAF.png

@takashi Thanks! That worked elegantly. Here are my final out puts after separating the sub-elements:

 

0684Q00000ArMaaQAF.png

 


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