Skip to main content
Solved

Parsing Complex XML with XFMap

  • November 7, 2017
  • 4 replies
  • 19 views

runneals
Supporter
Forum|alt.badge.img+28
<?xml version="1.0" encoding="utf-8"?>
<SDDOT>
  <item>...</item>
  <item>
    <id>497751</id>
    <status>active</status>
    <categories>
      <category>
        <name>conditions</name>
      </category>
    </categories>
    <descriptions>
      <description>
        <phrase>dry</phrase>
      </description>
    </descriptions>
    <locations>
      <location>
        <route>US-212</route>
        <direction>Both Directions</direction>
        <start>
          <lat>45.0056</lat>
          <lon>-102.8765</lon>
          <milepost>71.713</milepost>
          <landmark>
            <place>Mud Butte</place>
          </landmark>
        </start>
        <end>
          <lat>45.0231</lat>
          <lon>-102.0451</lon>
          <milepost>112.715</milepost>
          <landmark>
            <place>Junction South Dakota 73 South-Faith</place>
          </landmark>
        </end>
      </location>
      <location>
        <route>SD-73</route>
        <direction>Both Directions</direction>
        <start>
          <lat>45.0231</lat>
          <lon>-102.0451</lon>
          <milepost>166.445</milepost>
          <landmark>
            <place>Junction US 212 East-Faith</place>
          </landmark>
        </start>
        <end>
          <lat>45.0231</lat>
          <lon>-102.1095</lon>
          <milepost>169.608</milepost>
          <landmark>
            <place>Junction US 212 West</place>
          </landmark>
        </end>
      </location>
    </locations>
    <time>
      <start>
        <unixtime>1510070857</unixtime>
        <local_time>2017-11-07T09:07:37 MST</local_time>
      </start>
      <end>
        <unixtime>1510243620</unixtime>
        <local_time>2017-11-09T09:07:00 MST</local_time>
      </end>
      <announce>
        <unixtime>1510070857</unixtime>
        <local_time>2017-11-07T09:07:37 MST</local_time>
      </announce>
      <update>
        <unixtime>1510070857</unixtime>
        <local_time>2017-11-07T09:07:37 MST</local_time>
      </update>
    </time>
  </item>
  <item>...</item>
</SDDOT>

I need to get 2 features out of this, 1 for each <location> tag. How would I go about doing that? Currently I'm parsing out on each item. It threw an error when I attempted to read in the following:

<feature-map multi-feature-construction="true">
    <mapping match="item/locations/location">
       <feature-type> <literal expr="Feature"/> </feature-type>
    </mapping>
 </feature-map>

xfmap-sd-iris.xml

 

Best answer by daveatsafe

Hi @runneals,

The attached Xfmap should get you the locations with the attributes you want:

locations-xfmap.xml

Alternatively, you can use the Feature Paths Configuration Type in the XML reader read the locations from that XML data:

Enable Flattening to get the attributes:

The Feature paths is not as powerful as an Xfmap, but it is a lot simpler to use.

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.

4 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • Best Answer
  • November 7, 2017

Hi @runneals,

The attached Xfmap should get you the locations with the attributes you want:

locations-xfmap.xml

Alternatively, you can use the Feature Paths Configuration Type in the XML reader read the locations from that XML data:

Enable Flattening to get the attributes:

The Feature paths is not as powerful as an Xfmap, but it is a lot simpler to use.


runneals
Supporter
Forum|alt.badge.img+28
  • Author
  • Supporter
  • 322 replies
  • November 7, 2017

Hi @runneals,

The attached Xfmap should get you the locations with the attributes you want:

locations-xfmap.xml

Alternatively, you can use the Feature Paths Configuration Type in the XML reader read the locations from that XML data:

Enable Flattening to get the attributes:

The Feature paths is not as powerful as an Xfmap, but it is a lot simpler to use.

Is there any way to get the attributes outside of the locations path?

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • November 7, 2017
Is there any way to get the attributes outside of the locations path?
The easiest way to do that is to use the Feature Paths with Elements to Match set to 'SDDOT/item'. This will produce a single feature for each item with the locations as a list. Use a ListExploder to explode the locations.location{} list.

 

 

If you really need to use an Xfmap, I am attaching a modified copy of xfmap-sd-iris.xml that will also create a list for the locations. In the workspace, add a ListExploder to explode the list location{}.

 

location-list-xfmap.xml

 

 


runneals
Supporter
Forum|alt.badge.img+28
  • Author
  • Supporter
  • 322 replies
  • November 8, 2017

Hi @runneals,

The attached Xfmap should get you the locations with the attributes you want:

locations-xfmap.xml

Alternatively, you can use the Feature Paths Configuration Type in the XML reader read the locations from that XML data:

Enable Flattening to get the attributes:

The Feature paths is not as powerful as an Xfmap, but it is a lot simpler to use.

Thanks! I need to go outside my comfort zone and parse xml besides using xfmap