Question

XMLFragmenter - Exclude Attributes

  • 14 February 2018
  • 14 replies
  • 10 views

Badge

Hi,

I need to exclude all XML attributes beginning with "questionnaires.que_ans"

The following XML is being return from - HTTPCaller - XMLFragmenter -

Many thanks.

questionnaires.que_ans{0}.ans (encoded: utf-16) questionnaires.que_ans{0}.ans_value (encoded: utf-16) questionnaires.que_ans{0}.que (encoded: utf-16) questionnaires.que_ans{1}.ans (encoded: utf-16) questionnaires.que_ans{1}.ans_value (encoded: utf-16) questionnaires.que_ans{1}.que (encoded: utf-16) questionnaires.que_ans{2}.ans (encoded: utf-16) questionnaires.que_ans{2}.ans_value (encoded: utf-16) questionnaires.que_ans{2}.que (encoded: utf-16) questionnaires.que_ans{3}.ans (encoded: utf-16) questionnaires.que_ans{3}.ans_value (encoded: utf-16) questionnaires.que_ans{3}.que (encoded: utf-16) questionnaires.que_ans{4}.ans (encoded: utf-16) questionnaires.que_ans{4}.ans_value (encoded: utf-16) questionnaires.que_ans{4}.que (encoded: utf-16) questionnaires.que_ans{5}.ans (encoded: utf-16) questionnaires.que_ans{5}.ans_value (encoded: utf-16) questionnaires.que_ans{5}.que (encoded: utf-16) questionnaires.que_ans{5}.que_key (encoded: utf-16) questionnaires.que_ans{6}.ans (encoded: utf-16) questionnaires.que_ans{6}.ans_value (encoded: utf-16) questionnaires.que_ans{6}.que (encoded: utf-16) questionnaires.que_ans{6}.que_key (encoded: utf-16) questionnaires.que_ans{7}.ans (encoded: utf-16) questionnaires.que_ans{7}.ans_value (encoded: utf-16) questionnaires.que_ans{7}.que (encoded: utf-16) questionnaires.que_ans{8}.ans (encoded: utf-16) questionnaires.que_ans{8}.ans_value (encoded: utf-16) questionnaires.que_ans{8}.que (encoded: utf-16) questionnaires.que_ans{9}.ans (encoded: utf-16) questionnaires.que_ans{9}.que (encoded: utf-16) questionnaires.que_ans{9}.que_key (encoded: utf-16) questionnaires.que_ans{10}.ans (encoded: utf-16) questionnaires.que_ans{10}.que (encoded: utf-16) questionnaires.que_ans{10}.que_key (encoded: utf-16) questionnaires.que_ans{11}.ans (encoded: utf-16) questionnaires.que_ans{11}.que (encoded: utf-16) questionnaires.que_ans{11}.que_key (encoded: utf-16) questionnaires.que_ans{12}.ans (encoded: utf-16) questionnaires.que_ans{12}.que (encoded: utf-16) questionnaires.que_ans{12}.que_key (encoded: utf-16) questionnaires.que_ans{13}.ans (encoded: utf-16) questionnaires.que_ans{13}.que (encoded: utf-16) questionnaires.que_ans{13}.que_key (encoded: utf-16) questionnaires.que_ans{14}.ans (encoded: utf-16) questionnaires.que_ans{14}.que (encoded: utf-16) questionnaires.que_ans{14}.que_key (encoded: utf-16) questionnaires.que_ans{15}.ans (encoded: utf-16) questionnaires.que_ans{15}.que (encoded: utf-16) questionnaires.que_ans{15}.que_key (encoded: utf-16)

14 replies

Userlevel 2
Badge +17

Hi @ccdcpublic, you can ignore all the questionnaires/que_ans elements using the Ignore Specific Sub-Elements option in the XML Flatten Options parameters. See also the screenshot below.

Badge

Hi @ccdcpublic, you can ignore all the questionnaires/que_ans elements using the Ignore Specific Sub-Elements option in the XML Flatten Options parameters. See also the screenshot below.

Amazing - Thank you takashi

 

 

Badge

@takashi

Hi Takashi,

Many thanks for your assistance.

Ironically I was hoping the ignore the Questionnaires XML values but now it transpires their values are necessary.

My issue with the questionnaires is they are generated conditional on the eForm questions being answered - therefore we could receive 10 Questionnaire Values or 50 and so on.

I'm hoping to capture any ".que_key" values and create FME attributes with values from the .ans & .ans_values (as describe in the attached screen shot) for use throughout my workspace.

 

I've included a sample workspace with the initial XMLTemplater and HTTPCaller as an example - there is however a Public Key excluded in the XML within the XMLTemplater below which I can message you directly to you.

<cli:iPublicKey></cli:iPublicKey>

 

 

Thank you again for your assistance which is appreciated.

 

 

 

soap-xml-example.fmw

 

Userlevel 2
Badge +17

@takashi

Hi Takashi,

Many thanks for your assistance.

Ironically I was hoping the ignore the Questionnaires XML values but now it transpires their values are necessary.

My issue with the questionnaires is they are generated conditional on the eForm questions being answered - therefore we could receive 10 Questionnaire Values or 50 and so on.

I'm hoping to capture any ".que_key" values and create FME attributes with values from the .ans & .ans_values (as describe in the attached screen shot) for use throughout my workspace.

 

I've included a sample workspace with the initial XMLTemplater and HTTPCaller as an example - there is however a Public Key excluded in the XML within the XMLTemplater below which I can message you directly to you.

<cli:iPublicKey></cli:iPublicKey>

 

 

Thank you again for your assistance which is appreciated.

 

 

 

soap-xml-example.fmw

 

Hi @ccdcpublic, unfortunately I was not able to get any XML response containing elements with the public key from you. Could you please share a sample XML fragment containing at least one <report> element with its sub elements including <questionnaires> elements?

 

Userlevel 2
Badge +17

@takashi

Hi Takashi,

Many thanks for your assistance.

Ironically I was hoping the ignore the Questionnaires XML values but now it transpires their values are necessary.

My issue with the questionnaires is they are generated conditional on the eForm questions being answered - therefore we could receive 10 Questionnaire Values or 50 and so on.

I'm hoping to capture any ".que_key" values and create FME attributes with values from the .ans & .ans_values (as describe in the attached screen shot) for use throughout my workspace.

 

I've included a sample workspace with the initial XMLTemplater and HTTPCaller as an example - there is however a Public Key excluded in the XML within the XMLTemplater below which I can message you directly to you.

<cli:iPublicKey></cli:iPublicKey>

 

 

Thank you again for your assistance which is appreciated.

 

 

 

soap-xml-example.fmw

 

OK, I was able to get a valid XML. I pasted a wrong key....

 

 

Userlevel 2
Badge +17

@takashi

Hi Takashi,

Many thanks for your assistance.

Ironically I was hoping the ignore the Questionnaires XML values but now it transpires their values are necessary.

My issue with the questionnaires is they are generated conditional on the eForm questions being answered - therefore we could receive 10 Questionnaire Values or 50 and so on.

I'm hoping to capture any ".que_key" values and create FME attributes with values from the .ans & .ans_values (as describe in the attached screen shot) for use throughout my workspace.

 

I've included a sample workspace with the initial XMLTemplater and HTTPCaller as an example - there is however a Public Key excluded in the XML within the XMLTemplater below which I can message you directly to you.

<cli:iPublicKey></cli:iPublicKey>

 

 

Thank you again for your assistance which is appreciated.

 

0684Q00000ArKAtQAN.png

 

 

soap-xml-example.fmw

 

If I understand the requirement correctly, an XQuery expression might be effective.

 

0684Q00000ArMapQAF.png

 

XQuery Expression:

 

for $q in //questionnaires/que_ans[@que_key="ZAC_ASSISTED_TYPE"]
return (
    fme:set-attribute('ZAC_ASSISTED_ANS', $q/ans/text()),
    fme:set-attribute('ZAC_ASSISTED_ANS_VALUE', $q/ans_value/text())

Badge

@takashi

Hi Takashi,

Many thanks for your assistance.

Ironically I was hoping the ignore the Questionnaires XML values but now it transpires their values are necessary.

My issue with the questionnaires is they are generated conditional on the eForm questions being answered - therefore we could receive 10 Questionnaire Values or 50 and so on.

I'm hoping to capture any ".que_key" values and create FME attributes with values from the .ans & .ans_values (as describe in the attached screen shot) for use throughout my workspace.

 

I've included a sample workspace with the initial XMLTemplater and HTTPCaller as an example - there is however a Public Key excluded in the XML within the XMLTemplater below which I can message you directly to you.

<cli:iPublicKey></cli:iPublicKey>

 

 

Thank you again for your assistance which is appreciated.

 

 

 

soap-xml-example.fmw

 

Thank you Takashi - the expression looks almost complete.

 

 

Unfortunately we cannot assign fixed value of "ZAC_ASSISTED_TYPE" as this may change & we have multiple attributes to assign, therefore we need to source this from the XML response value for any ".que_key" returned -

 

Hope I've explained this correctly.

 

 

Many thanks

 

 

 

 

 

Userlevel 2
Badge +17

@takashi

Hi Takashi,

Many thanks for your assistance.

Ironically I was hoping the ignore the Questionnaires XML values but now it transpires their values are necessary.

My issue with the questionnaires is they are generated conditional on the eForm questions being answered - therefore we could receive 10 Questionnaire Values or 50 and so on.

I'm hoping to capture any ".que_key" values and create FME attributes with values from the .ans & .ans_values (as describe in the attached screen shot) for use throughout my workspace.

 

I've included a sample workspace with the initial XMLTemplater and HTTPCaller as an example - there is however a Public Key excluded in the XML within the XMLTemplater below which I can message you directly to you.

<cli:iPublicKey></cli:iPublicKey>

 

 

Thank you again for your assistance which is appreciated.

 

0684Q00000ArKAtQAN.png

 

 

soap-xml-example.fmw

 

This expression creates attributes '<key name>_ANS' and '<key name>_ANS_VALUE' for every existing 'que_key'. Note: I didn't implement the function to remove the suffix '_TYPE' from a key name, since the keys except 'ZAC_ASSISTED_TYPE' don't have the suffix '_TYPE' but the rules to determine which suffix should be removed are unknown. If you need to remove a suffix, please clarify the rules.

 

for $q in //questionnaires/que_ans
let $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())

 

Userlevel 2
Badge +17
If I understand the requirement correctly, an XQuery expression might be effective.

 

0684Q00000ArMapQAF.png

 

XQuery Expression:

 

for $q in //questionnaires/que_ans[@que_key="ZAC_ASSISTED_TYPE"]
return (
    fme:set-attribute('ZAC_ASSISTED_ANS', $q/ans/text()),
    fme:set-attribute('ZAC_ASSISTED_ANS_VALUE', $q/ans_value/text())

This expression creates attributes '_ANS' and '_ANS_VALUE' for every existing 'que_key'. Note: I didn't implement the function to remove the suffix '_TYPE' from a key name, since the keys except 'ZAC_ASSISTED_TYPE' don't have the suffix '_TYPE' but the rules to determine which suffix should be removed are unknown. If you need to remove a suffix, please clarify the rules.

 

for $q in //questionnaires/que_ans
let $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())

 

Badge
This expression creates attributes '<key name>_ANS' and '<key name>_ANS_VALUE' for every existing 'que_key'. Note: I didn't implement the function to remove the suffix '_TYPE' from a key name, since the keys except 'ZAC_ASSISTED_TYPE' don't have the suffix '_TYPE' but the rules to determine which suffix should be removed are unknown. If you need to remove a suffix, please clarify the rules.

 

for $q in //questionnaires/que_ans
let $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())

 

takashi - your expression is perfect, delivering exactly what we require....Many thanks again for your assistance -

 

0684Q00000ArMxQQAV.png

 

 

Badge
This expression creates attributes '<key name>_ANS' and '<key name>_ANS_VALUE' for every existing 'que_key'. Note: I didn't implement the function to remove the suffix '_TYPE' from a key name, since the keys except 'ZAC_ASSISTED_TYPE' don't have the suffix '_TYPE' but the rules to determine which suffix should be removed are unknown. If you need to remove a suffix, please clarify the rules.

 

for $q in //questionnaires/que_ans
let $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())

 

Hi Takashi,

 

 

Apologies for returning to this post but I've noticed an issue which I cannot resolve.

 

Via Data Inspector the attributes are appearing as expected from your

 

 expression.  However, for only 4 instances the "que_key" I've noticed are not present in Transformer(s) Attribute selector, example for ZMB.... and ZSC.... attached.

 

 

Once again your assistance would be appreciated.

 

 

attributes-not-shown-in-transformers.png

Userlevel 2
Badge +17
This expression creates attributes '<key name>_ANS' and '<key name>_ANS_VALUE' for every existing 'que_key'. Note: I didn't implement the function to remove the suffix '_TYPE' from a key name, since the keys except 'ZAC_ASSISTED_TYPE' don't have the suffix '_TYPE' but the rules to determine which suffix should be removed are unknown. If you need to remove a suffix, please clarify the rules.

 

for $q in //questionnaires/que_ans
let $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())

 

FME Workbench cannot automatically expose attribute names which will be created at run-time with scripts including XQuery, Python, Tcl, etc. If necessary, you have to manually expose those attribute names through the 'Attributes to Expose' parameter in the XMLXQueryExtractor or an AttributeExposer transformer.

 

 

Badge

@takashi

Hello Takashi,

Apologies for re-visting this post but I've come across an issue since using multiple records where the captured attributes do not relate to the record being processed.

All xml records are generated based on the same status code, each successful record in the process will then have it's status changed to prevent repetition. I've attempted to setup a sampler to only handle the first record - would it be possible for the XMLXQueryExtractor to creating attributes for the single sample record rather than all records?

Many thanks

xmlxqueryextractor-single-sample.png

Userlevel 2
Badge +17

@takashi

Hello Takashi,

Apologies for re-visting this post but I've come across an issue since using multiple records where the captured attributes do not relate to the record being processed.

All xml records are generated based on the same status code, each successful record in the process will then have it's status changed to prevent repetition. I've attempted to setup a sampler to only handle the first record - would it be possible for the XMLXQueryExtractor to creating attributes for the single sample record rather than all records?

Many thanks

xmlxqueryextractor-single-sample.png

The XMLXQueryExtractor does not have any filtering functionality. If you need to process only the first feature, I think the Sampler would be a good solution.

 

 

Reply