Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Xquery for DRB

This xquery module allows execute xquery on DRB nodes.

Using this module

To include this module into your project, the drb-xquery module shall be referenced into requirement.txt file, or the following pip line can be run:

pip install drb-xquery

Example for execute a query on xml node:

node_file = DrbFileFactory().create("/path_xml_file/namefile.xml")
node = XmlNodeFactory().create(node_file)

# request node named 2A_Tile_ID with ns as namespace
query = DrbXQuery("/ns:Level-2A_Tile_ID")
result = query.execute(node)

Result is always a list of value or dynamic context

Example with external variables:

# create the query from  String   
query = DrbXQuery("declare variable $x external; "
                 "declare variable $y external := 5; $x+$y")

list_var = {'x': 9, 'y': 12}

result = query.execute(node, list_var)

# result[0] == 21

Command line

A command line is available for use this module.

The name of the command line is xquery

xquery --help

Usage: drb-xquery-cmd [OPTIONS]

  This command evaluates the XQuery script provided as a string or a file. The
  output of the evaluation is printed out in the standard output. The output
  format may have several forms according to the resulting sequence. Basically
  the resulting nodes are output as XML fragments, the attributes not attached
  to nodes are written as in XML but prefixed with '@' symbol and finally, the
  atomic values are printed without decoration, according to the XML Schema
  lexical space definitions. All items of the output sequence are comma
  separated. A '()' result denotes the empty sequence.

Options:
  -s, --string TEXT    Command line string to be evaluated as XQuery script.
                       This parameter cannot be used jointly with -f. At least
                       -s or -f is to be set.
  -f, --file TEXT      Path to a file containing the sctript to be evaluated.
                       This parameter cannot be used jointly with -s. At least
                       -f or -s is to be set..
  -n, --url-node TEXT  Url to a node, in drb meaning, that give the context of
                       the query. It can be the pathof a xml file for example on
                       which the xquery willbe executed
  -V, --verbose
  -v, --variable TEXT  Variable define -v <QName> <value> [ as <type>].Pushes an
                       external variable in the environment prior to parse and
                       evaluate the XQuery script. The variable is pushed in the
                       the environment altough it has not been declared has an
                       external variable, to provide it to the potential nested
                       XQuerys (e.g. a call to evaluate-uri() built-in
                       function). <QName> is the qualified name of the variable
                       to declare whether <value> is a string to bind as value
                       of the variable. If <QName> matches a typed external
                       variable declared in the script, <value> is converted to
                       that type before being bound. The trailing "as <type>" is
                       optional and shall follow the XQuery sequence type
                       declaration (e.g. as xs:integer+ )
  --help               Show this message and exit.

Example with string query

xquery  -s "declare variable \$x external; declare variable \$y external := 5; \$x +\$y" -v x  9 -v y 2
11
xquery  -s "/Level-2A_Tile_ID/Test_FLF[@name_attr='test_two' or serie='B'][position() < 5][2]" --url-node "./tests/files/MTD_TL.xml"

<Test_FLF xmlns="nc3" xmlns:ns1="SB" name_attr="test_one" index="03" occurence="4" atr="quattre"><name>first_doublon</name><ns1:french>premier</ns1:french><number>one</number><serie>B</serie><elt>This is 4</elt></Test_FLF> 

Example with file query and url node

xquery  -f "./tests/files/test.xq" --url-node "./tests/files/MTD_TL.xml"
first_doublon

Limitations and differences with W3C standard

The data() function return only the value of elt

for example :

 data(element root {element foo {"child"}, " parent" })

return in W3C standard:

child parent

return in this implementation:

parent

The infinity value is allowed for Decimal as for float: In W3C infinity is only allowed for float or double.

The type xs:double is identical to xs:float The type xs:long, xs:short, xs:byte are identical to xs:integer

Other limitations

Some types are not defined like: xs:anyURI xs:untypedAtomic ...

Some functions are not yet implemented like: yearMonthDuration deep-equal remove processing-instruction exactly-one ...

Some expressions are not (yet) implemented like: group by order by typeswitch treat as map and array are not defined too

Warning for user using drb java implementation of Xquery

When using positional predicates, you should be aware that the to keyword does not work as you might expect when used in predicates. If you want the first three products, it may be tempting to use the syntax:

doc("catalog.xml")/catalog/product[1 to 3]

However, this will raise an error[*] because the predicate evaluates to multiple numbers instead of a single one. You can, however, use the syntax:

doc("catalog.xml")/catalog/product[position() = (1 to 3)]

For compare function the result is only -1,0, 1 , in java thi function return a negative value that can be different to -1 or a positive value that represent a difference between the two string...

Metadata

Release files for drb-xquery 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drb-xquery 1.0.4
File Size Uploaded Provenance Actions
drb-xquery-1.0.4.tar.gz 3.4 MB Without provenance Details for drb-xquery-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drb-xquery 1.0.4
File Interpreter ABI Platform Actions
drb_xquery-1.0.4-py3-none-any.whl Python 3 none any Details for drb_xquery-1.0.4-py3-none-any.whl

Total release size: 3.6 MB

Release files / drb-xquery-1.0.4.tar.gz

Download URL drb-xquery-1.0.4.tar.gz
Size 3.4 MB
Tags Source
SHA-256 checksum
How to use checksums
eb92398c24d4c019b4e46de63817e11ca2d4ee5c5f1b4155560962277c1e06d3
BLAKE2b-256 checksum
How to use checksums
8090ff5040caeaf730504c6db09136d1355e516f26436ea1538031170d432893
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.11.4 pkginfo/1.8.3 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.13

Release files / drb_xquery-1.0.4-py3-none-any.whl

Download URL drb_xquery-1.0.4-py3-none-any.whl
Size 185.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b453c4b1428a657211fecf4555ffbf9eae9557698b077c3d019b98228825c640
BLAKE2b-256 checksum
How to use checksums
f9dd5baebffc8bd6b45b6861dcfaea6511f48e7d447bb7835ef12b5fbf1a25a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.11.4 pkginfo/1.8.3 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.13

Security for drb-xquery 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page