XML Binding

dieter dieter at handshake.de
Wed Sep 9 10:20:48 CEST 2015


Palpandi <palpandi111 at gmail.com> writes:

> Is it better to use pyxb than lxml?
>
> What are the advantages of lxml and pyxb?

"pyxb" has a different aim than "lxml".

"lxml" is a general purpose library to process XML documents.
It gives you an interface to the document's resources (elements,
attributes, comments, processing instructions) on a low level
independ from the document type.

"pyxb" is different: there, you start with an XML schema description.
You use "pyxb" to generate Python bindings for this schema.
With such a binding generated, "pyxb" can parse XML documents
following a known XML schema into the corresponding binding.
The binding objects expose child (XML) elements and (XML) attributes as
attributes of the binding object. Thus, the Python interface
(as defined by the binding) is highly dependent on the type (aka XML schema)
of the document.


I use "lxml" for either simple XML processing or when the XML documents
are not described by an XML schema. I use "pyxb" when the XML documents
has an associated complex schema and the processing is rather complex.



More information about the Python-list mailing list