ruledxml

A library to transform XML to XML using business rules written in python.

I don't get it. XML to XML? So it's XSLT!
Yes, a subset. But writing XSLT is cumbersome. In the spirit of business rule engines, we want to be able to write basic logical rules with as little programming knowledge as possible.
Okay… but subset? So it means not every transformation is possible?
Yes, for example you cannot specify the following: for every element X in the source XML file, create an element Y. But if there are exactly 3 X elements, create only one Y element. Also nesting cannot be arbitrarily complex: for every element X, create Y elements which are nested in each other. Those usecases cannot be modelled with RuledXml.
Okay, I don't need so complex transformations. But text nodes can be arbitrarily combined and numeric values arbitrarily computed?
Yes, once you have defined from where to which XML element data flows, you have computationally unlimited power. Every value is provided as string and you can arbitrarily convert it into another data type. This is because we use python for rules.
But python is complicated?
No, I think it's fairly suitable to use and easy to learn.
Get to the point! Shall I use it?
Yes, if all of the following criteria are satisfied:
  • you want to transform XML to another XML structure
  • you don't have a programming-skilled person available to maintain your transformation rules
  • you don't need extensive XML namespace support for the input XML file (will be fixed in future versions)
  • your transformations are not too complex (as explained above)
  • you can install python3 on your machine

Example

Usecase

Given a name and surname in a source XML file, concatenate those names to a username element in the target XML file.

Rule

@source("/member/surname")
@source("/member/name")
@destination("/participant/username")
def rule_name_and_surname(name, surname):
    return name + ' ' + surname

Transformation:

<?xml version="1.0"?>
<member>
  <name>John</name>
  <surname>Doe</surname>
</member>

<?xml version="1.0" encoding="utf-8"?>
<participant>
  <username>John Doe</username>
</participant>

Project data

Author:Lukas Prokop
License:BSD 3-clause
Development date:July 2015
Release number:1.0.0
Software stack:python3, lxml

Feedback? Bugs? Enhancement proposals? Email me.

Installation

  1. Download the latest python 3.x release.
  2. You need to use pip (python's package manager) to download the python module RuledXml namely “ruledxml”.
  3. Run ruledxml <inputfile.xml> <rulesfile.py> <outputfile.xml> on your command line to transform a file.