Skip to main content
Question

How can I map XML element attributes?

  • July 23, 2014
  • 8 replies
  • 63 views

Forum|alt.badge.img
I am trying to flatten an xml file which contains the following Elements

 

 

 <?xml version="1.0" encoding="UTF-8"?> <elements total="877" num="877"> <element id="242698" v="2" pv="1" x="1109133" y="6970266" geom="POINT (9.9699121998145532 52.9278245931941953)" priority="0" type="99" approved="1" current="1" latest="1" date="2014-07-08 13:15:52" user="10" user_token="Friedrich"> <types> <type id="562"/> </types> <periods> <period id="32"/> </periods> <events> <event type="1" begin_prefix="~" begin_year="1790" end_prefix="~" end_year="1790"/> </events> <aspects> <a id="1" l="de" v="Alter Schafstall"/> <a id="2" p="5" code="6"/> <a id="3" p="10" code="3"/> <a id="39" l="de" v="Zehn "/> <a id="41" l="de" v="Zwischen"/> <a id="57" l="de" v="etwa 40m"/> </aspects> <relations/> <media> <medium id="79236"/> <medium id="79237"/> </media> </element> </elements>
 

 

It party works when I define the "elements to match" as <element> but the attributes in the <a> tag are not being flattened. They get translated into the "xml_fragments" field which contains xml-style code. I don´t understand where this "xml_fragments" comes from and would like simply map the attributes into their own fields like "a.id" "a.l" or "a.v".

 

 

Could anyone explain to me what is going on here?
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.

8 replies

takashi
Celebrity
  • July 23, 2014
Hi,

 

 

Since there are multiple <a> elements under an <element>, those attributes will be flattened as structured list, like this.

 

aspect.a{}.code

 

aspect.a{}.id

 

aspect.a{}.l

 

aspect.a{}.p

 

aspect.a{}.v

 

 

Takashi

Forum|alt.badge.img
This isn´t happening though. FME creates the field "xml_fragment" and basically inputs the whole xml file including the structural elements <, > / etc. I really don´t understand why this is happening! Any help would be appreciated.

 

 


takashi
Celebrity
  • July 24, 2014
If you specify "element" to Elements to Match parameter, "a" and its attributes will be stored in structured list as I mentioned in my previous post.

 

As long as seeing your image, I guess that you've specified "a" to Elements to Match.

 

 

Anyway, when using Feature Paths as configuration type, the XML reader adds "xml_fragment" to the reader feature type by default. This attribute stores an element matched with specified element (i.e. "a" in this case) as an XML document.

 

I think there are no problems, just ignore if you don't need it.

 

If you don't want to extract "xml_fragment" anyhow, consider using xfMap instead of Feature Paths.

Forum|alt.badge.img
Thanks....but in my case then, why is the following list element empty?

 

 

 <a id="1" l="de" v="Alter Schafstall"/> 
 

 

As I understand it,  the element "v" which contains the text "Alter Schafstall" should be contained within the list a.v

 

 

Am I correct?

 

 


takashi
Celebrity
  • July 24, 2014
"a.v" is an attribute, is not a list attribute.

 

Yes, "a.v" of the first feature should contain "Alter Schafstall".

takashi
Celebrity
  • July 24, 2014
Connect an Inspector to the reader feature type and run the workspace. You can see how XML elements and attribute values are extracted.

Forum|alt.badge.img

OK...when I define "elements to match" as "a", then I obtain a table with the string "Alter Schaftstall" under element a.v! But when i the "element to match" is defined as element, then I expect aspect.a.v to include the string.  Looking at the XML Document, Element is the parent, and "aspects" and "a" are children and "v" is the attribute. So why can´t I get the string when I define "elements"?


takashi
Celebrity
  • July 24, 2014
Because there are multiple <a> elements in an <elements> element. By default, the XML reader configures list attribute for multiple children which have same tag name.

 

Probably these list attributes occur in the reader feature type when you specify <elements> to Elements to Match.

 

element.aspects.a{}.v

 

element.aspects.a{}.p

 

and so on.

 

 

If this case, you will have to extract elements of the lists in the data flow after reading.

 

See here about lists.

 

http://docs.safe.com/fme/html/FME_Transformers/Default.htm#Categories/lists.htm%3FTocPath%3DFME%20Transformers%7CLists%7C_____0