[lxml-dev] lxml 2.2 validation question

Stefan Behnel stefan_ml at behnel.de
Wed May 20 09:47:23 CEST 2009


James Slagle wrote:
> My main issue is with an external tool I'm passing my generated xml
> to.  This tool expects no prefixes on the elements, but prefixes on
> the attributes, and thus needs the namespace declared with a prefix
> and as the default.  Yes, I know this is broken, and the tool needs to
> be fixed to be more flexible :).

... "to support XML namespaces", you mean. ;-)


> I was mainly wanting to know if it was possible to use lxml to
> generate xml output in this manner.

I recall adding a namespace setup rule that explicitly prefers the
prefixed namespace over an equivalent default namespace when you define
both on the same node. This is because otherwise you end up with a similar
problem with unnamespaced attributes on namespaced elements.

The output you get is a side effect of that fix, so, no, there isn't a way
to define a namespace as both the default namespace and a prefixed
namespace, and basically let lxml ignore the prefixed namespace in favour
of the default.

That said, was there actually a reason why you defined the namespace
prefix in the first place? Why isn't the default namespace enough to do
what you want? (Note that the prefix used in the schema is independent of
the one used in the document, that's what I meant with prefixes being
'overrated'.)

Stefan



More information about the lxml-dev mailing list