Hello @thijsknapen
There currently isn't an XQuery function in FME to determine if an attribute is null or not. I have filed this request as an enhancement and will let you know once it has been implemented.
Our development team did mention it is possible to use the fme:get-json-attribute()
XQuery function as it does have special handling for null attributes. The downside is using this function will cause warnings and errors in the log since the attribute does not contain valid JSON which is not ideal.
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
{
if ( not(fme:has-attribute("b")) )
then ()
else if ( not(fme:get-attribute("b") = "") )
then (<b>{fme:get-attribute("b")}</b>)
else if (xs:string(fme:get-json-attribute("b")) = "null")
then (<b xsi:nil="true" nilReason="unknown"/>)
else if ( fme:get-attribute("b") = "")
then (<b/>)
else ()
}
<c>value_c</c>
</dummyXML>
I hope this information helps.
Hello @thijsknapen
There currently isn't an XQuery function in FME to determine if an attribute is null or not. I have filed this request as an enhancement and will let you know once it has been implemented.
Our development team did mention it is possible to use the fme:get-json-attribute()
XQuery function as it does have special handling for null attributes. The downside is using this function will cause warnings and errors in the log since the attribute does not contain valid JSON which is not ideal.
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
{
if ( not(fme:has-attribute("b")) )
then ()
else if ( not(fme:get-attribute("b") = "") )
then (<b>{fme:get-attribute("b")}</b>)
else if (xs:string(fme:get-json-attribute("b")) = "null")
then (<b xsi:nil="true" nilReason="unknown"/>)
else if ( fme:get-attribute("b") = "")
then (<b/>)
else ()
}
<c>value_c</c>
</dummyXML>
I hope this information helps.
Hi @debbiatsafe ,
Thanks for filing the enhancement request! It would be great if that could be implemented.
Regarding the fme:get-json-attribute() XQuery function, I indeed noticed that that does support null values. I suppose that may be part of JSONiq, which is an extention to XQuery? In section 3.1. Simple Datatypes I found that;
JSONiq adds one new data type: js:null, derived from xs:anyAtomicType. js:null has a singleton value space containing the value null i2]. The lexical representation of an instance of js:null is the string "null".
Thanks for sharing the workaround. I noticed that it works, but due to the warnings and errors you mentioned, I think I prefer my initial workaround (map <null> to specific string, and check if value equals that string).
Also, by parsing the null value that is fetched from the fme:get-json-attribute() function to a string, I think you effectively might do the same. Specifically, you still perform a stringwise comparison, and you wouldn't be able to distinct a string value "null", from a <null> value that can be fetched as a JSON null type and then parsed to the string "null". So, instead of line 8 in your example, I thought about using;
else if (fme:get-json-attribute("b") eq null)
but that doesn't seem to be working for me. I am a bit confused why not.
Specifically, when I use an XMLXQueryExtractor transformer using the statement;
xs:string(jn:null()) eq "null"
it results in 'true' (I think effectively why your workaround works).
However, when I then use either
jn:null() eq null
or
null eq null
i get an empty string as a result, where I would have also expected 'true'.
Specifically, section 6.16. Changes to value comparison semantics of the JSONiq doc would lead me to believe that that should also result in 'true'.
But I might have gone a bit off topic. I think we agree that the situation is not ideal and I'm really grateful for the enhancement request. Furthermore there are multiple workarounds for the mean time
Hello @thijsknapen
There currently isn't an XQuery function in FME to determine if an attribute is null or not. I have filed this request as an enhancement and will let you know once it has been implemented.
Our development team did mention it is possible to use the fme:get-json-attribute()
XQuery function as it does have special handling for null attributes. The downside is using this function will cause warnings and errors in the log since the attribute does not contain valid JSON which is not ideal.
<dummyXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a>value_a</a>
{
if ( not(fme:has-attribute("b")) )
then ()
else if ( not(fme:get-attribute("b") = "") )
then (<b>{fme:get-attribute("b")}</b>)
else if (xs:string(fme:get-json-attribute("b")) = "null")
then (<b xsi:nil="true" nilReason="unknown"/>)
else if ( fme:get-attribute("b") = "")
then (<b/>)
else ()
}
<c>value_c</c>
</dummyXML>
I hope this information helps.
Hi @debbiatsafe ,
Is it maybe possible to share an update on the status of the enhancement request? Is it being considered/planned, etc?
In the end I'm of course mostly interested in if, and if so when I can expect this enhancement to make it into a new version of FME, but I understand that it's difficult to provide an exact timeline for this.
Hi @debbiatsafe ,
Is it maybe possible to share an update on the status of the enhancement request? Is it being considered/planned, etc?
In the end I'm of course mostly interested in if, and if so when I can expect this enhancement to make it into a new version of FME, but I understand that it's difficult to provide an exact timeline for this.
Hello @thijsknapen
Support for a new FME XQuery function that is able to distinguish between a null attribute value and an empty string is planned (tracked as FMEENGINE-76086). However, there is not an exact timeline for this addition yet. I hope this information helps!
Hi @debbiatsafe ,
Is it maybe possible to share an update on the status of the enhancement request? Is it being considered/planned, etc?
In the end I'm of course mostly interested in if, and if so when I can expect this enhancement to make it into a new version of FME, but I understand that it's difficult to provide an exact timeline for this.
Check, thanks for the update @debbiatsafe !
Good to hear that this is planned.