Given an XML file. Transform it into another XML file using a rules file. A rules file reads some element, process them and returns a new value which is written to an XML path. Rules are inspired by Business Rule Engines such as Intellect.
Installation
Installation with source package:
python3 setup.py install
pip3 install -r requirements.txt
Installation from PyPI:
pip3 install ruledxml
Run the testsuite:
Start python3
Run import ruledxml.tests
Run ruledxml.tests.runall()
Rules
Rules are designed to be written with little technical knowledge. However, not all transformations (comparable to XSLT) are possible. If elements occur multiple times in the source XML, the capabilities are limited.
Rules are written in the python programming language:
@source("/root/body/header")
@destination("/html/body/article/h1")
def ruleFirstHeader(header):
return header + "!"
The first element at XPath /root/body/header is read, its text content is looked up and passed as argument header to the function ruleFirstHeader.
If the source element does not exist, an empty string is supplied. Be aware that source parameters are always strings.
The rule returns the original header appended with an exclamation mark. The return value is written to the destination XPath /html/body/article/h1. All non-existing elements will be created. If an element already exists, the first match is taken.
Required elements
A source of errors in that design is when elements do not exist and an empty string is supplied as argument. This is a silent error.
You can specify required elements in a variable input_required which is interpreted before the actual processing starts:
input_required = [
"/root/body/header"
]
If the element /root/body/header does not exist in the source XML file, a ValueError is thrown.
Non-empty elements
Similarly to required elements, we have non-empty elements. Paths mentioned in the input_nonempty variable are required to yield nonempty values. Otherwise an error is thrown and processing aborted.
Implementation
A little bit of lxml and lots of decorator magic ;)
License
3-claused BSD license. Hence you can use the software for whatever you like, if you want to mention my name in your software product, you need to ask me.
cheers, meisterluk <admin@lukas-prokop.at>
Metadata
Release files for ruledxml 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ruledxml-1.6.0.tar.gz | 17.4 kB | Without provenance | Details for ruledxml-1.6.0.tar.gz |
Release files / ruledxml-1.6.0.tar.gz
| Download URL | ruledxml-1.6.0.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
942cb36271568bbdeb31ed4d509d3ca03701c50d7cb2551fb07a47834ae74c11
|
|
BLAKE2b-256 checksum How to use checksums |
89ef720f9edaf662046f22630c1e70e7242f9d36edf6fdf855873bab89f2cbd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ruledxml 1.6.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.