Question

XMLXQueryExtractor from sampler

  • 2 March 2018
  • 9 replies
  • 11 views

Badge

Hi

Is it possible to have xmlxqueryextractor to read from the source of a Sampler.

My issue is the source XML file has multiple records therefore I only wish to process them singularly from a sampler of 1st...

Cheers


9 replies

Userlevel 2
Badge +17

I suppose this question is derived from "XMLFragmenter - Exclude Attributes.

I cannot understand correctly what you mean with "the source XML file has multiple records", since usually the terminology "record" is not used in XML operations.

If you are looking for an XQuery syntax to extract an element at a specific position within a sequence of sub elements belonging to an identical parent element, the following example might help you.

Assuming that the source XML looks like this,

<?xml version="1.0"?>
<parent>
  <child>
    <attribute>11</attribute>
    <attribute>12</attribute>
    <attribute>13</attribute>
  </child>
  <child>
    <attribute>21</attribute>
    <attribute>22</attribute>
    <attribute>23</attribute>
  </child>
  <child>
    <attribute>31</attribute>
    <attribute>32</attribute>
    <attribute>33</attribute>
  </child>
</parent>

this XQuery expression extracts the values of <attribute> elements under the first <child> element belonging to the <parent> element.

for $a in //parent/child[1]/attribute
return $a/text()

That is, [<position>] following to an element name in an XML path works to specify the position of an element to be extracted. Note that the position of an element should be specified with 1-based sequential number, unlike FME uses 0-based number as the index for list elements.

If you set the expression to the XQuery Expression parameter in an XMLXQueryExtractor, and set "List Attribute" to the Return Value parameter, the output feature would have this list attribute.

Attribute(encoded: utf-8): `_results{0}' has value `11'
Attribute(encoded: utf-8): `_results{1}' has value `12'
Attribute(encoded: utf-8): `_results{2}' has value `13'

If the example above couldn't help you, please paste an XML example (a simplified but valid XML fragment) and explain what you need to get from the XML.

Badge

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return ( fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) )

 

Thank you again for your assistance.

sample-xml-reports-report-id.xml

Userlevel 2
Badge +17

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.  

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

 for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return (    fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) ) 

 

 Thank you again for your assistance.

sample-xml-reports-report-id.xml

Your attached XML cannot be downloaded. Not sure the reason, but it could have corrupted.

 

I guess that the reports element contains multiple child elements (called report?) and each child element have an attribute called report_id. Is it right?

 

If so, and if you need to fragment the reports element into each child element as individual features, the XMLFragmenter might help you. 

 

Input? A feature has a single <reports> element containing multiple <report> element.

 

<reports>
  <report report_id="1" />
  <report report_id="2" />
  <report report_id="3" />
</reports>
Desired result? Each feature has a single <report> element.

 

<report report_id="1" />
<report report_id="2" />
<report report_id="3" />
Badge

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return ( fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) )

 

Thank you again for your assistance.

sample-xml-reports-report-id.xml

takashi-v1.fmw

 

 

Hi takashi, I've attached a copy of the workspace which may be easier than me attempting to explain.

 

 

Public key will be messaged across.

 

 

Many thanks again for your assistance.

 

 

Userlevel 2
Badge +17

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return ( fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) )

 

Thank you again for your assistance.

sample-xml-reports-report-id.xml

I can see that the XMLFragmenter in your workspace outputs features, each of which contains an XML fragment <report>, and it has a child element <report_id>.

 

Then, what do you want to get from them?

 

Can you please explain using a simplified example, as I used above? It's hard to find your interest parts from the full XML document. Please extract only important parts to explain the question.

 

Badge

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return ( fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) )

 

Thank you again for your assistance.

sample-xml-reports-report-id.xml

Hello takashi,

 

 

Attached Excel Doc is what I'm hopinh to acheive from the XML ...

 

 

xml-goals.xlsx

 

 

Many thanks.

 

 

 

Userlevel 2
Badge +17

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return ( fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) )

 

Thank you again for your assistance.

sample-xml-reports-report-id.xml

It seems that the requirement is to just filter the "report" features created from the XML document according to the value of "category.form_name". If I understand the requirement correctly, this workflow should work as expected. No need to modify the XQuery expression, but note that the Source XML attribute for the XMLXQueryExtractor is "xml_fragment" (i.e. each <report> element).

 

 

 

Userlevel 2
Badge +17

@takashi

Hello takashi

Thank you for your time.Attached is a typical example of an XML document.

 

The xml document has an element for "reports" which contain multiple unique "report_id".Each "report_id" contains a Service Request for either "SBC_MISSED_BIN", "SBC_ASSISTED", "SBC_COMPLAINTS" or "SBC_SPECIALS"If your script below could process each "report_id" in turn this may resolve the issue?

 

for $q in //questionnaires/que_anslet $k := xs:string($q/@que_key) where $k ne '' return ( fme:set-attribute($k||'_ANS', $q/ans/text()),fme:set-attribute($k||'_ANS_VALUE', $q/ans_value/text()) )

 

Thank you again for your assistance.

sample-xml-reports-report-id.xml

This is the workspace (not including source XML): xmlfragmenter-xmlxqueryextractor-attributefilter.fmw (FME 2017.1.2.1)

 

 

Badge
This is the workspace (not including source XML): xmlfragmenter-xmlxqueryextractor-attributefilter.fmw (FME 2017.1.2.1)

 

 

Hello takashi,

 

 

Early signs are looking promising.

 

 

Many thanks for your support and patience.

 

 

Much appreciated

 

 

Reply