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:

from drb.xquery import DrbXQuery
import drb.topics.resolver as resolver

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

Example for execute same request on two nodes

from drb.xquery import DrbXQuery
import drb.topics.resolver as resolver

node_A = resolver.create("/path_xml_file/namefileA.xml")
node_B = resolver.create("/path_xml_file/namefileB.xml")
# request node named 2A_Tile_ID with ns as namespace
query = DrbXQuery("/ns:Level-2A_Tile_ID")
result = query.execute(node_A, node_B)

Result is always a list of value or dynamic context

Example with external variables:

from drb.xquery import DrbXQuery

# create the query from  String   
query = DrbXQuery("declare variable $x external; "
                 "declare variable $y external := 5; $x+$y")
result = query.execute(None, x=9, y=12)
# result[0] == 21

Command line

A command line xquery is provided by this package:

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

Special function drb:xml()

This implementation have a function drb:xml([NODE]) This function take an item [NODE] as argument, And return a string that represent the item argument If the item is a DrbNode or a node, we return the representation of this node as xml (with namespace, child, ...) If the item is not a node but have a name and a value (like attribute) It return <[NAME]>[Value as string]</[NAME]> Otherwise it return the value as String.

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.2.0

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.2.0
File Size Uploaded Provenance Actions
drb-xquery-1.2.0.tar.gz 202.6 kB Without provenance Details for drb-xquery-1.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 392.2 kB

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

Download URL drb-xquery-1.2.0.tar.gz
Size 202.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dfa68c2af69fa2a5f47ceffaa6b34c7acac70798f99aafee5bd17cfe09070548
BLAKE2b-256 checksum
How to use checksums
30f3564b08ddaf81d63e34f137e2a8928e75b7f41ad5a6e875ab06d1c1d85faa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

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

Download URL drb_xquery-1.2.0-py3-none-any.whl
Size 189.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8f05e9c66d2f7d3e032f4c864d78576bd16e5c3eefa48fce57bf00411117156
BLAKE2b-256 checksum
How to use checksums
de9103dae7e2f297e261d9ca05e9fbad991705fa00ce39eab9f6add4b723acc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Security for drb-xquery 1.2.0

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