I have posted this question on the help forum two times in the last weeks, but I probably do it the wrong way. The post is placed on the bottom of the list and states ‘post awaiting moderation’.
I am trying to generate valid XML with Pyxb, by instantiating new objects and filling them with data form a database.
When I set the namespace of a schema to default, the generated XML is not valid.
I get the following error:
ERROR: Element '{http://sample}ValueAmount', attribute 'currencyID': The attribute 'currencyID' is not allowed.
I have found that the reason for this error is the fact that the attributes in the XML are not prefixed with the namespaceprefix.
Is there a way I can get Pyxb to keep the namespaceprefixes on attributes when I set the namespace to default?
Or is this an error?
The project I am working on has an XML schema with qualified elements and qualified attributes.
When I validate this XML, I get the error above. This is because the currencyID attribute has no prefix, while it is a qualified attribute.
The W3C reccomendation on Namespases: http://www.w3.org/TR/REC-xml-names/#scoping-defaulting gives the following explanation:
6.2 Namespace Defaulting
The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.
A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.
If there is a default namespace declaration in scope, the expanded name corresponding to an unprefixed element name has the URI of the default namespace as its namespace name. If there is no default namespace declaration in scope, the namespace name has no value. The namespace name for an unprefixed attribute name always has no value. In all cases, the local name is local part (which is of course the same as the unprefixed name itself).
When the namespace is not set to default, every element and attribute in the generated XML is prefixed correctly with the namespaceprefix. The XML is valid.
I was unaware that SourceForge had added moderation to these forums, and though I see your postings in a moderation queue I can't actually see their content, so don't know why they were held (or what good a moderation feature might be). I've at least added my email address as a notification address so this shouldn't happen again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Pyxb team,
I have posted this question on the help forum two times in the last weeks, but I probably do it the wrong way. The post is placed on the bottom of the list and states ‘post awaiting moderation’.
I am trying to generate valid XML with Pyxb, by instantiating new objects and filling them with data form a database.
When I set the namespace of a schema to default, the generated XML is not valid.
I get the following error:
ERROR: Element '{http://sample}ValueAmount', attribute 'currencyID': The attribute 'currencyID' is not allowed.
I have found that the reason for this error is the fact that the attributes in the XML are not prefixed with the namespaceprefix.
Is there a way I can get Pyxb to keep the namespaceprefixes on attributes when I set the namespace to default?
Or is this an error?
The project I am working on has an XML schema with qualified elements and qualified attributes.
This is an example of the XSD:
The generation of XML is done with:
This python program gives the following XML:
When I validate this XML, I get the error above. This is because the currencyID attribute has no prefix, while it is a qualified attribute.
The W3C reccomendation on Namespases: http://www.w3.org/TR/REC-xml-names/#scoping-defaulting gives the following explanation:
6.2 Namespace Defaulting
The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.
A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear.
If there is a default namespace declaration in scope, the expanded name corresponding to an unprefixed element name has the URI of the default namespace as its namespace name. If there is no default namespace declaration in scope, the namespace name has no value. The namespace name for an unprefixed attribute name always has no value. In all cases, the local name is local part (which is of course the same as the unprefixed name itself).
When the namespace is not set to default, every element and attribute in the generated XML is prefixed correctly with the namespaceprefix. The XML is valid.
The XML output needed for my project is this:
Is there a way to get this XML using Pyxb?
This is a bug. You can get the XML you desire if you apply the patches that fix issue #202.
Thanks for reporting the problem.
Last edit: Peter A. Bigot 2013-07-10
I was unaware that SourceForge had added moderation to these forums, and though I see your postings in a moderation queue I can't actually see their content, so don't know why they were held (or what good a moderation feature might be). I've at least added my email address as a notification address so this shouldn't happen again.
Hello Peter,
After applying the patch, it works all perfect.
Thank you for the quick response.
Regards,
Bart