Search code examples
xqueryexist-dboxygenxml

OXygen Implementation of XQuery: Why Can't Path Expressions Return Attribute Values Directly?


Previous Stack questions indicate that in certain implementations of XQuery, returning attributes directly from a path expression (e.g. `$doc//@name') fails to display results and yields runtime errors:

Can't select XML attributes with Oxygen XQuery implementation; Oxygen XPath emits result

XQuery unable to select attribute

While attribute values can be returned using the string() or data() functions, I'm still confused as to why this limitation exists at all. The former link suggests that it is indeed the OXygen IDE itself, independent of the XQuery processor. However, when I try to return attributes directly I get the following runtime error message:

error: Failed to invoke method retrieveFirstChunk in class  org.exist.xmlrpc.RpcConnection: org.xml.sax.SAXException: 
Error SENR0001: attribute 'notBefore' has no parent element

Since this error message is from the processor, could the type of processor play a role? I'm using eXist-db as my data source and processor.


Solution

  • I don't know the specifics of the particular products involved, but the basic situation is that XQuery can return an attribute or sequence of attributes, but the standard XQuery 1.0 serialization methods can't display the value. For example a query like //@id will select a sequence of attributes all named "id" and there is no way of serializing this as XML. The "adaptive" serialization method was introduced in XQuery 3.1 largely as a response to this problem: it's designed to display the results in human-readable form, not to output well-formed XML.