Xquery
Queries an XML document using the Xquery language.
Usage
xquery (indata, xml-attr, xquery : outdata)
Details
XML data stored in attribute xml-attr of relation indata is
queried using xquery, with its results stored in outdata,
joined back with its input (i.e., a dependent join).
Queries are processed using the SAXON XQuery SDK.
Notes
- This version of Xquery replaces the earlier Quip-based version.
- xml-attr can be either a CHAR or DOCUMENT relational attribute
type. The latter is usually obtained from a prior
Xwrapper or Rel2xml
operator. In the case of the former, the data must be legal XML and
is internally converted into a Document before processing.
Known Bugs
Example
Using the input:
RELATION document: xmltext char
<?xml version="1.0"?> <books> <book> <title>Title1</title> <author>Author1</author> </book> <book> <title>Title2</title> <author>Author2</author> </book> <book><title>Title3</title> <author>Author1</author> </book> </books>
RELATION query: dummy char
<titles> { for $b in ./books/book where $b/author/text() = "Author1" return $b/title } </titles>
when executing the plan:
PLAN test
{
INPUT: stream document, stream query
OUTPUT: stream result
BODY
{
xquery (document, "xmltext", query, "answer_doc" : query-result)
xml2rel (query-result, "answer_doc", "/titles", "index" : result)
}
}
OR:
PLAN test
{
INPUT: stream document
OUTPUT: stream result
BODY
{
xquery (document, "xmltext", "<titles> { for $b in ./books/book where $b/author/text() = \"Author1\" return $b/title } </titles>", "answer_doc" : query-result)
xml2rel (query-result, "answer_doc", "/titles", "index" : result)
}
}
generates the following output:
----------------------------------------------
RELATION: uxquery1_result
attrs: index, xmltext, answer_doc, title
----------------------------------------------
0|<?xml version="1.0"?> <books> <book> <title>Title1</title> <author>Author1</author> </book> <book> <title>Title2</title> <author>Author2</author> </book> <book> <title>Title3</title> <author>Author1</author> </book> </books>, <?xml version="1.0" encoding="UTF-8"?>
<titles>
<title>Title1</title>
<title>Title3</title>
</titles>|Title1
1|<?xml version="1.0"?> <books> <book> <title>Title1</title> <author>Author1</author> </book> <book> <title>Title2</title> <author>Author2</author> </book> <book> <title>Title3</title> <author>Author1</author> </book> </books>, <?xml version="1.0" encoding="UTF-8"?>
<titles>
<title>Title1</title>
<title>Title3</title>
</titles>|Title3
----------------------------------------------