you are not creating an instance of the xsd-with-hyphens element, you're creating an instance of the XsdWithHyphens complex type that is not associated with an element. Since toxml isn't told what element to use (and any number of elements might use that type), it emits the type name instead. Arguably, it should emit a warning about having a type that's not bound to an element. I'll add a tracker ticket for that.
However, no patch to PyXB is needed to fix this. You could use:
which uses the Python "constructor" corresponding to the element (not its underlying type) to create the instance and associate the element with it. Note that pyxbgen renamed xsd-with-hyphens because it is not a valid Python identifier:
WARNING:pyxb.binding.generate:Element {urn:com:xsd:with:hyphens:xsd-with-hyphens}xsd-with-hyphens renamed to xsd_with_hyphens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
oh i see. My bad. I'm trying to convert from generateDS to PyXB. I didn't see anything in the documentation regarding this, though I'm sure I missed it. I'll have to go back and read it again slowly so I don't make these simple mistakes again.
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using this schema:
xsd-with-hyphens.xsd
I created a python class using:
Then I created this python test:
I get the following xml:
ns1:XsdWithHyphens is wrong. The xml should be this:
I haven't been able to figure out how to force this other than supplying a parameter to the toxml() function which I'd rather not do.
Any suggestions?
In your code:
you are not creating an instance of the xsd-with-hyphens element, you're creating an instance of the XsdWithHyphens complex type that is not associated with an element. Since toxml isn't told what element to use (and any number of elements might use that type), it emits the type name instead. Arguably, it should emit a warning about having a type that's not bound to an element. I'll add a tracker ticket for that.
However, no patch to PyXB is needed to fix this. You could use:
to associate the element with the instance, but the preferred solution would be:
which uses the Python "constructor" corresponding to the element (not its underlying type) to create the instance and associate the element with it. Note that pyxbgen renamed xsd-with-hyphens because it is not a valid Python identifier:
Also note that renaming the Python identifier had no effect on the generated XML; both alternatives generate the following:
oh i see. My bad. I'm trying to convert from generateDS to PyXB. I didn't see anything in the documentation regarding this, though I'm sure I missed it. I'll have to go back and read it again slowly so I don't make these simple mistakes again.
Thanks!