XPath-expressions
This is a small, lightweight Python 3.5+ library to aide in the manipulations of xpath expressions. It allows you to manipulate them as Python objects with Python expressions and operators.
Install
pip install xpath-expressions
Quickstart
from xpath import Expression, Attribute
root_node = Expression('/root')
print(root_node.children) # /root/*
print(root_node.name) # name(/root)
print(root_node.attributes[1]) # /root/@*[1]
print(root_node / 'abc' / 'def') # /root/abc/def
# Filtering expressions:
print(root_node.text == 'abc') # /root/text()='abc'
expr = Attribute('abc') == 'def'
print(expr) # @abc='def'
print(root_node.children[expr]) # /root/*[@abc='def']
# The library handles quoting for you:
expr = Attribute('abc') == "def'"
filtered2 = root_node.children[expr] # /root/*[@abc="def'"]
# You can use xpath functions:
from xpath import func
# Pass arguments like usual
expr = func.string_length(root_node.name)
print(expr) # string-length(name(/root/))
# And treat those as normal expressions
print(expr == 5) # string-length(name(/root/)) == 5
# The library normalizes python reserved names:
print(func.or_()) # or()
# Use custom namespaces
from xpath import Functions
ns_functions = Functions('my-ns:')
print(ns_functions.something()) # my-ns:something()
Metadata
Release files for xpath-expressions 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xpath-expressions-1.0.2.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xpath_expressions-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 kB
Release files / xpath-expressions-1.0.2.tar.gz
| Download URL | xpath-expressions-1.0.2.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03cd059ebd4b0b4fb5ee3924d88c7269233cc55de3857ad415d33936c6b1c27a
|
|
BLAKE2b-256 checksum How to use checksums |
2dc846e6efccaef9ed5b76077ec6ee0e97163b11a4b87d8c2a85b23294dc76a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.7 Darwin/19.4.0
|
Release files / xpath_expressions-1.0.2-py3-none-any.whl
| Download URL | xpath_expressions-1.0.2-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1735044772bee6f0826a3f00e5cc9b7710de901f345e98a8ecd3df91f44792a
|
|
BLAKE2b-256 checksum How to use checksums |
51a1bf514394d1e2b804abe87d34f3bd2f95276f360172aff53b3a4f3173519c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.7 Darwin/19.4.0
|