• Keine Ergebnisse gefunden

3.3 Relationships with W3C Concepts

4.1.1 XQuery and XLinks

Although the W3C XML Query (XQuery) Requirements [XMQ04, Sec. 3.3.4/3.4.12 (“References”)] explicitly state that

“the XML Query Data Model MUST include support for references, including both ref-erences within an XML document and refref-erences from one XML document to another”

and that

“queries MUST be able to traverse intra- and inter-document references”,

neither XPath nor XQuery can handle XLinks to their full extent. This is mentioned in the XML Query Requirements (for each of the quoted requirements, it states that “this

requirement has been partially met”) and will be analyzed in a general way below.

Considering intra-document references, i.e.IDREFattributes referencingID attributes in the same document, theid()function allows for dereferencing them in order to access the referenced elements. On the other hand, for accessing remote documents, thedoc() function can be used but in XPath or XQuery there is not yet complete support for evaluating XPointers remotely. For a simple XLink element, users can select the XPointer found in thexlink:href attribute with

for $pointer in

doc(”http://. . . /countries.xml”)//country[@car code=”B”]/capital/@xlink:href but XQuery cannot be told to resolve it because a data item (i.e., the value of the xlink:href attribute) can not be considered as an XPath query. This is currently not possible in the base language, nor can it be achieved by the functions and operators given in theXQuery 1.0 and XPath 2.0 Functions and Operators specification [XPQ06].

The following paragraphs show that a solution for handling shorthand pointers based on XQuery exists while xpointer() expressions consisting of XPath queries can not be resolved by XQuery in general.

Simple XPointers for ID-Dereferencing. Simple XPointers actually consisting of an id()function application of the form url#xpointer(id(string))for dereferencing elements by theirIDcan be resolved by combining thedoc()andid()functions. These pointers are equivalent to “shorthand pointers” likehttp://. . . /country.xml#D(pointing to Germany) in [XPt03b] (cf. Section 2.3.1). In [LS04, Section 7.4.2], a solution by an XQuery user-defined function is given which is restricted to such simple XPointers:

declare namespace func=”http://www.example.org/functions”;

declare function func:follow-xlink($href as xs:string) as item()*

{

let $docValue := substring-before($href,”#”) let $x := substring-after($href,”#xpointer(id(’”) let $idValue := substring-before($x,”’)”)

return

doc($docValue)/id($idValue) };

The URI supplied as $href argument is split into its host part containing the path to the referenced document and its fragment identifier which is separated from the host part by “#”. The solution in [LS04] assumes the fragment identifier to contain an XPointer that consists of an id() function call for dereferencing an element by its id.

Thus, general XPointers based on arbitrary XPath expressions can not be handled. In order to return the referenced element, an XPath expression is dynamically constructed and evaluated. It consists of two steps: the first resolves the remote document with the doc() function and the second consists of the id() function for dereferencing the appropriate element. Note that here, the relevant computed variables are passed to XPath functions as arguments.

XPath Expressions in XPointers. In the general case, instead of id($idValue), the xpointer() scheme allows for the use of arbitrary XPath expressions. Similar to the solution proposed above, a naive approach might look as follows:

declare namespace func=”http://www.example.org/functions”;

declare function func:follow-xlink($href as xs:string) as item()*

{

let $docValue := substring-before($href,”#”) let $x := substring-after($href,”#xpointer(”) let $path := substring-before($x,”)”)

return

doc($docValue)/ $path };

The remote document is resolved in the same way like above. However, instead of extracting a simple id value, we have to access the XPath expression contained in the xpointer() directive using the auxiliary variable $x. Intuitively, we then concatenate the doc()function call and the obtained path expression but this will result in an error. This dynamically constructed XPath expression is not accepted by XQuery because it is not allowed to use a variable as location step. This can also not be programmed using the currentXQuery 1.0 and XPath 2.0 Functions and Operators [XPQ06]. Note that in case that the XPointer is not based on an id() function call, the proposed solution given in [LS04, Section 7.4.2] explicitly returns a message “XPointer Syntax nicht unterst¨utzt” (XPointer syntax not supported). However, there exist XPath implementations and other proposals that allow for this dynamic evaluation.

Dynamically Evaluating Data Items as Queries. For the dynamic evaluation of an XPath expression supplied as a string variable, the XPath/XQuery implementation Saxon [SAX] offers anextension functionsaxon:evaluate(string). This function also works on remote documents. The above function can be expressed as

declare namespace func=”http://www.example.org/functions”;

declare function func:follow-xlink($href as xs:string) as item()*

{

let $docValue := substring-before($href,”#”)

let $path := replace($href, ”^.*#xpointer.(.*).$”,”$1”) let $expr := concat(”doc(’”, $docValue, ”’)”, $path) return

saxon:evaluate($expr) };

Thus, the data item $path containing the XPath expression used in the XPointer is dynamically evaluated on the remote document.

The XQuery extension proposed in [RBHS04] introduces a mechanism for evaluating XPath/XQuery expressions on remote servers that offer an appropriate interface. The syntax reads as “execute aturi xquery{xquery }”. Using this technique, the above query could be stated as follows:

declare namespace func=”http://www.example.org/functions”;

declare function func:follow-xlink($href as xs:string) as item()*

{

let $docValue := substring-before($href,”#”)

let $path := replace($href, ”^.*#xpointer.(.*).$”,”$1”) return

execute at $docValue xquery { $path} };

Then, queries use –similar to theid()function– anexplicitdereferencing. For instance, in order to query the population of Belgium’s capital in the distributedMondialdatabase that models the capital relationship for countries by an XLink to the appropriate city:

doc(”http://. . . /countries.xml”)//country[@car code=”B”]/

capital/ func:follow-xlink(@xlink:href) /population

In contrast to that explicit approach,we argue that, if XLink references are used, implicit dereferencing is preferable. Seeing interlinked XML instances as one integrated view (that e.g. has to conform to a target schema), we want to provide a way to use original XPath/XQuerywithout any syntactical extensions thus enabling users to transparently query the data while XLinks are dereferencedimplicitly like

doc(”http://. . . /countries.xml”)//country[@car code=”B”]/capital/population.

In this section, we showed that it is not (yet) possible to query XML instances containing simple XLinks with XPath/XQuery. As simple XLinks are just a syntactic variant of specific extended XLinks, it also follows that XQuery can not handle extended XLinks.