Download ciao Reference Manual - pdf

Transcript
Chapter 179: XML query library
699
179 XML query library
Author(s): Jos Manuel Gmez Prez.
Version: 0.1 (2003/12/1, 13:24:9 CET)
This package provides a language suitable for querying XML documents from a Prolog program. Constraint programming expresions can be included in order to prune search as soon as
possible, i.e. upon constraint unsatisfability, improving efficiency. Also, facilities are offerd to
improve search speed by transforming XML documents into Prolog programs, hence reducing
search to just running the program and taking advantage of Prolog’s indexing capabilities.
Queries in an XML document have a recursive tree structructure that permits to detail the
search on the XML element sought, its attributes, and its children. As a suffix, a constraint
programming expression can be added. Queries return value for the free variables included (in
case of success), and checks whether the XML document structure matches that depicted by the
query itself.
The operators introduced are described below:
• @ Delimits a subquery on an elment’s attribute, such as product@val(product_name,
"car"), the first argument being the attribute name and the second its value. Any of
them can be free variables, being possible to write queries like product@val(Name, "car"),
intended to find the ’Name’ of attributes of element product whose value is the string "car".
• :: The right-hand side of the subexpression delimited by this operator is a query on the
children elements of the element described on its left-hand side.
• with Declares the constraints the items sought must satisfy.
Some examples of this query language (more can be found in the examples directory):
• Example A:
product@val(product_name,"car")::(quantity(X),
’time-left’(Y),
negotiation::preference::price(Z))
with X * Z .>. Y
• Example B:
nitf::head::docdata::’doc-id’@val(’id-string’,"020918050")::(Y),
body::’body.head’::abstract::p(X)