Skip to main content
Solved

Extracting data using the XML Flattener

  • September 28, 2020
  • 5 replies
  • 257 views

nedwaterman
Contributor
Forum|alt.badge.img+9

fmeHi,

 

I'm trying to use the XML Flattener to extract the attributes from an xml response_body:

 

<loggers>

<summary>

<APIVersion>DatagateAdmin V2.48 (14-Sep-2020 12:38)</APIVersion>

<accountID>5279</accountID>

<accountName>Main Account for all SWW loggers</accountName>

<accountOwnerId></accountOwnerId>

<accountHighestMessage>4526752363</accountHighestMessage>

<accountUpdateTime>2020-09-28 08:39:17.6</accountUpdateTime>

<accountNumLoggers>2563</accountNumLoggers>

<CentreLongitude>-3.86433819774539</CentreLongitude>

<CentreLatitude>50.6236029248117</CentreLatitude>

<MinimumPhoto>0</MinimumPhoto>

</summary>

<logger>

<loggerid>74508</loggerid>

<mobileNumber>447924658356</mobileNumber>

<dateLastMessageReceived>2019-12-17 16:00:00.0</dateLastMessageReceived>

<type>FW-102-001</type>

<serialNumber>80823</serialNumber>

<loggerOwner>5279</loggerOwner>

<LogRate></LogRate>

<RST>2019-02-05 12:30:00.0</RST>

<RET>0001-01-01 00:00:00.0</RET>

<gsmDataNumber>0</gsmDataNumber>

<notes></notes>

<batteryCondition>0</batteryCondition>

<signalStrength>0</signalStrength>

<lastReportedVersion>3.90</lastReportedVersion>

<dateCreated>2015-09-29 09:41:00.0</dateCreated>

<dateUpdated>2018-11-16 16:40:36.6</dateUpdated>

<heightAOD>99.0</heightAOD>

<startDate>2015-09-29 00:00:00.0</startDate>

<endDate>2020-10-04 00:00:00.0</endDate>

<maintenanceflag>False</maintenanceflag>

<id>74508</id>

<owner>5279</owner>

<siteId>1201</siteId>

<siteName>Sweyns Lease PCC</siteName>

<SiteNotes></SiteNotes>

<latitude>50.805459823648</latitude>

<longitude>-1.469778435546914</longitude>

<channel1Type></channel1Type>

<flowPulseFactor1>0.1</flowPulseFactor1>

<meterRead1Value>0</meterRead1Value>

<meterRead1Date>0001-01-01 00:00:00.0</meterRead1Date>

<channel2Type></channel2Type>

<flowPulseFactor2>1</flowPulseFactor2>

<meterRead2Value>0</meterRead2Value>

<meterRead2Date>0001-01-01 00:00:00.0</meterRead2Date>

<channels>

<channel number="1">

<channelName></channelName>

<offset>0</offset>

<flowPulseFactor>0.1</flowPulseFactor>

<meterReadValue>0</meterReadValue>

<meterReadDate>0001-01-01 00:00:00.0</meterReadDate>

<calvalue>0.1</calvalue>

<loggercalvalue>0.1</loggercalvalue>

<loggeroffset>0</loggeroffset>

<ignoreloggervalues>0</ignoreloggervalues>

<is4to20>0</is4to20>

<loggerIs4to20>0</loggerIs4to20>

<invertnegativevalues>0</invertnegativevalues>

<lastValue>27.4</lastValue>

<lastValueDate>2019-12-17 12:30:00.0</lastValueDate>

<measurement id = "0">

<name></name>

<reference></reference>

<units>

<symbols>m</symbols>

</units>

</measurement>

</channel>

</logger>

 

I'm using these parameters in the XML Flattener to grab the loggers.logger.loggerid but its not working:

 

Any idea what I am doing wrong? I'm aware that there are multple logger values so have also tried loggerid{}, loggerid{*} but neither work.

 

Thanks

Neil

Best answer by ebygomm

Hi David

Thank you - however, its only produced a single record rather than all the loggerid's in the xml response. Does FME make a list of these I need to expose?

If you want multiple features, I'd use the XMLFragmenter rather than the XMLFlattener

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

david_r
Celebrity
  • 8392 replies
  • September 28, 2020

Have you tried setting Elements to Match to "logger" rather than "loggers"?

That should give you one FME feature per logger instance.


nedwaterman
Contributor
Forum|alt.badge.img+9
  • Author
  • Contributor
  • 69 replies
  • September 28, 2020

Hi David

Thank you - however, its only produced a single record rather than all the loggerid's in the xml response. Does FME make a list of these I need to expose?


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • Best Answer
  • September 28, 2020

Hi David

Thank you - however, its only produced a single record rather than all the loggerid's in the xml response. Does FME make a list of these I need to expose?

If you want multiple features, I'd use the XMLFragmenter rather than the XMLFlattener


nedwaterman
Contributor
Forum|alt.badge.img+9
  • Author
  • Contributor
  • 69 replies
  • September 28, 2020

If you want multiple features, I'd use the XMLFragmenter rather than the XMLFlattener

I have been, but I need to extract data from twodifferent elements in the api: <logger> and <channel>. They are both children of <loggers> but the joining field <loggerid> only appears in <logger> and not <channel> so I can't join the data back to one row

 

 


david_r
Celebrity
  • 8392 replies
  • September 28, 2020

If you want multiple features, I'd use the XMLFragmenter rather than the XMLFlattener

If you flatten the Logger elements, the channels will be present as "sub-attributes" using dot-notation, or as a list if there are several of them.

To see how this works, send the output of the XMLFragmenter to the Inspector and click on a feature to look at the Feature Information. The attributes visible here are the ones you'll need to expose in the XMLFragmenter.

Example:

2020-09-28 12_04_13-FME Data Inspector - 2020.1