Skip to main content
Solved

How to build logic into XML Formatter


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

View original
Did this help you find an answer to your question?

2 replies

takashi
Influencer
  • 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
takashi wrote:

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!

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings