Skyron: XML document transformations in Python

Skyron is a small Python package which allows an XML document to be processed in a way which is described by a text file called a recipe. Skyron recipes identify interesting data in the XML document and say what is to be done with that interesting data. A Skyron recipe contains a set of descriptions of XML elements and a set of instructions of what to do with the data available at the beginning and at the end of an XML element. At the beginning of an element the values of any the attributes are available as is the text in the enclosing element which has been seen so far.

For example:

<outer> this is text <inner attribute1='value 1' attribute2='value2'> xxx </inner>

When the start of the <inner> element is encountered three strings are available to the recipe:

1.    attribute1 with the value "value 1"

2.    attribute2 with the value "value 2"

3.    The special identifier $ with the value " this is text "

When the end of the <inner> element is encountered one string is available to the recipe:

1.    The special identifier $ with the value " xxx "

The recipe specifies what is to be done with these strings when they are encountered. The operations specified are performed by calling Python methods. Skyron comes with a set of methods which allows recipes to build Python tuples, lists and dictionaries. It also has methods which allow Python classes to be instantiated using the data in the XML document. Of course, user supplied methods can be called and chunks of Python code can be included in the recipe which are dynamically compiled and executed as needed. Skyron recipes can be used to perform XML data binding. That is to say an XML document can be used to generate a set of Python objects. However that is only one use for a recipe. It can also be used to "execute" an XML document performing actions whilst parsing the document and producing no resultant objects. Thirdly it can be used to transform a document into one or more text files.

Skyron recipes are XML documents. In fact Skyron bootstraps itself by using a recipe to transform recipes into the data structures needed by the program.

What Skyron is not

Skyron is not a schema language. In general Skyron recipes do not impose a structure on the document. Unless told otherwise, the document processor just ignores elements it does not recognise. Skyron can be told to complain if it sees an unexpected element but if you want to do proper document validation you should use a proper schema language like Relax NG or the W3C schema language.

What is missing?

This is the first release of Skyron. It has several major deficiencies. These are the ones I know about:

·      It does not support Namespaces

·      It does not support element recipe subclassing which makes recipes far longer than the need to be

·      Error reporting is very basic

·      Installation of the package is very basic

·      There will be bugs

 Download

The code is released under a modified BSD style licence which is compatible with the GPL. The package can be downloaded from here.

Support

There is a Skyron mailing list here. This list provides isupport for users of the system.