when I run an XQuery command-line, it works as long as the result is an element.
When I extend that XQuery to get an attribute-value only, it fails with this error:
SENR0001: Cannot serialize a free-standing attribute node (net.sf.saxon.om.NameOfNode)
So, this works
java -cp ...Saxon-HE-9.9.0-1.jar net.sf.saxon.Query
-s:AnyXMLFileAvailable.xml -qs:/
this fails:
java -cp ...Saxon-HE-9.9.0-1.jar net.sf.saxon.Query
s:AnyXMLFileAvailable.xml -qs://@*
As long as there is at least one attribute anywhere in the XML, this command will fail with the above error
I believe this can be fixed with licensed Saxon which enables use of the
-outval:recover
switch. Is there another way?
The default serialization method when you run Query from the command line is "xml"; I have been reluctant to change that for compatibility reasons. The "xml" serialization method fails when you try to serialize certain results, including maps, arrays, and attribute nodes.
If you set !method=adaptive on the command line (escaping the "!" with "\" if using bash) then serialization should never fail, it will produce some kind of representation of the query result. If the result is an attribute, it will represent it as name="value" which may or not be what you want. If you actually want just the string value of the attribute, then you need to extract this within the query, e.g. by using the string() or data() functions.
The -outval option is quite irrelevant, it's concerned with schema-validation of the query result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With