Question

I would like to use either xfMap or the XMLFragmenter on the attached xml file.

  • 21 October 2017
  • 3 replies
  • 1 view

Badge

I would like to use either xfMap or the XMLFragmenter on the attached complex xml file. I need the attributes as columns for each "area type". So for each area type the attributes would be: "area type", "description", "forecast-periods","flood status","warning prediction", "obs_site_description",etc.. This seems to be really difficult with the XMLFragmenter and I not proficient enough with xfMap either. If anyone has some example Workspaces I could use that would be great?


3 replies

Userlevel 2
Badge +17

Hi @johnm, basically you can extract all the values (attribute values and text contents of XML elements) under each "area" element with the regular XML reader with the default "Feature Paths" configuration mode (the mechanism is equivalent to XMLFragmenter) with XML Flatten options.

0684Q00000ArKJxQAN.png

In your XML document, there are cases that some elements occur multiple times under the same parent node. e.g. <forecast-period> elements under an <area> element, <text> elements under a <forecast-period> element, etc. Those multiple elements can be treated as list attributes.

However, they do not always occur two or more times. There are cases where they occur just once. In such a case, when configuring reader schema, the XML reader generates both regular attributes and list attribute by default for the same XML elements, and it would be troublesome to handle them.


To always read them as list attributes, you can modify the cardinality attribute of the Flatten options with the Advanced mode, like this.

0684Q00000ArK3TQAV.png

cardinality="
*/forecast-period{}/element{}/+
*/forecast-period{}/text{}/p{}/+
*/forecast-period{}/text{}/+
*/forecast-period{}/+
*/hazard{}/area-list/area{}/+
*/hazard{}/+
+{?}"

With the setting above, The reader feature type and reading result looks like this.

0684Q00000ArJvvQAF.png

You can then extract desired values with list operations on the workflow. 

Alternatively, if you can thoroughly specify the XML paths of all the XML elements and attributes that contain your finally required values, there might be a smarter way using XQuery expressions.

Badge

Hi @takashi, Thank you again for your prompt reply. It was a great help to me. If I find a smarter way I will let you know. Cheers, John

Badge

Hi @takashi, Thank you for your prompt reply. It was a great help to me. If I find a smarter way I will let you know. Cheers, John

Reply