Skip to main content
Solved

How to build logic into XML Formatter

  • April 23, 2018
  • 2 replies
  • 20 views

Forum|alt.badge.img

I have an XML Formatter transformer translating a query out of a MSSQL Database.  My XLD does not allow empty values, thus I always need to go through with a text editor and find XML Tags which look like this:

<KONTAKT2_EMAIL></KONTAKT2_EMAIL>

and change them to this:

<KONTAKT2_EMAIL xsi:nil="true" />

This is rather time consuming and I would like to perform this validity check in fme. I would therefore need to build in the following logic into the xml formatter transformer:

if Value = Null then XML Tag ends with xsi:nil="true" />

Any idea how to achieve this?

Best answer by takashi

Hi @robertdbuckley, the XMLXQueryUpdater with this XQuery expression replaces value of every existing xsi:nil attribute with true and adds xsi:nil attribute with value of true to every empty element missing xsi:nil attribute.

for $x in //*[fn:empty(child::*) and fn:empty(text())]
return if (fn:exists($x/@xsi:nil))
    then replace value of node $x/@xsi:nil with true
    else insert node attribute xsi:nil {true} into $x

0684Q00000ArLCYQA3.png

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.

2 replies

takashi
Celebrity
  • 7843 replies
  • Best Answer
  • April 23, 2018

Hi @robertdbuckley, the XMLXQueryUpdater with this XQuery expression replaces value of every existing xsi:nil attribute with true and adds xsi:nil attribute with value of true to every empty element missing xsi:nil attribute.

for $x in //*[fn:empty(child::*) and fn:empty(text())]
return if (fn:exists($x/@xsi:nil))
    then replace value of node $x/@xsi:nil with true
    else insert node attribute xsi:nil {true} into $x

0684Q00000ArLCYQA3.png


Forum|alt.badge.img

Hi @robertdbuckley, the XMLXQueryUpdater with this XQuery expression replaces value of every existing xsi:nil attribute with true and adds xsi:nil attribute with value of true to every empty element missing xsi:nil attribute.

for $x in //*[fn:empty(child::*) and fn:empty(text())]
return if (fn:exists($x/@xsi:nil))
    then replace value of node $x/@xsi:nil with true
    else insert node attribute xsi:nil {true} into $x

0684Q00000ArLCYQA3.png

Thank you!