I want to create a DOM based for the SDF robot model format based on the XSD at http://sdformat.org/schemas/root.xsd for a Blender export to a Robot simulator (Gazebo) in an open source project.
It is defined by <xsd:element name="inertia">
(I guess this is not an anonymous element) but in pyxb it is mapped to an anonymous class CTD_ANON_54 and not to sdf_dom.inertia which I would expect.
When I want to build up the DOM from python, is there a way to refer to the CDT_ANON_54 class in a better way?</xsd:element>
How is the correct way to do this with pyxb?
Best
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no such thing as an anonymous element (all have names), but if the type of an element is provided in the body of the element's element[sic] (as opposed to being named by a type attribute in the element opening tag) then the element's type is anonymous. This is indicated by the name generated (CTD_ANON_54 indicates the 54th anonymous complex type definition encountered in the schema.)
XML types are converted to PyXB classes; XML elements are converted to a constructor function that creates an instance of the type and binds the element name to it. If inertia is a global element in the schema used to generate the sdf_dom bindings then you should be able to create instances of it using sdf_dom.inertia(args...).
Unfortuantely, the sdf_dom.inertia does not exist (not a global element then?). I tried using pyxb.BIND but I did not really figure out how to use it in this case (I tried multiple variants such as nertia.append(pyxb.BIND(1,1,1,1,1,1) – also with kwargs).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I note that the element in the schema is inertial, not inertia. Other than that, I don't see why you wouldn't be able to create one (it is a top-level hence global element): I'd have to generate the bindings to test it myself, which I can't do at ths time.
Last edit: Peter A. Bigot 2016-09-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, I'm back and have been able to play with that schema.
Whoever coded that schema appears be unfamiliar with how XML schema work. While it does accept the set of documents it's probably intended to accept, it also accepts an infinite number of unlikely documents because of the use of choice where sequence or all would be far more appropriate.
For completeness, starting with bindings generated with this command:
It's acceptable because although the innermost choice model groups produce either zero or one element (i.e. the element is optional), they are all contained in choice model groups that require one or more of any alternative.
The use of an outer unbounded choice model group means that every element can appear multiple times; in PyXB terms that the elements are plural. Thus they are represented by lists, not instances of types. A PyXB.BIND instance is compatible only with instances of types.
So you can construct instances using the following code which is part of the i.py program attached:
Hi,
I want to create a DOM based for the SDF robot model format based on the XSD at
http://sdformat.org/schemas/root.xsd for a Blender export to a Robot simulator (Gazebo) in an open source project.
I encounter a problem with the <inertia> tag defined in
http://sdformat.org/schemas/inertial.xsd</inertia>
It is defined by <xsd:element name="inertia">
(I guess this is not an anonymous element) but in pyxb it is mapped to an anonymous class CTD_ANON_54 and not to sdf_dom.inertia which I would expect.
When I want to build up the DOM from python, is there a way to refer to the CDT_ANON_54 class in a better way?</xsd:element>
How is the correct way to do this with pyxb?
Best
There is no such thing as an anonymous element (all have names), but if the type of an element is provided in the body of the element's element[sic] (as opposed to being named by a
typeattribute in the element opening tag) then the element's type is anonymous. This is indicated by the name generated (CTD_ANON_54indicates the 54th anonymous complex type definition encountered in the schema.)XML types are converted to PyXB classes; XML elements are converted to a constructor function that creates an instance of the type and binds the element name to it. If
inertiais a global element in the schema used to generate thesdf_dombindings then you should be able to create instances of it usingsdf_dom.inertia(args...).Please review the examples and discussion here.
Thanks for your answer.
Unfortuantely, the sdf_dom.inertia does not exist (not a global element then?). I tried using pyxb.BIND but I did not really figure out how to use it in this case (I tried multiple variants such as nertia.append(pyxb.BIND(1,1,1,1,1,1) – also with kwargs).
I note that the element in the schema is
inertial, notinertia. Other than that, I don't see why you wouldn't be able to create one (it is a top-level hence global element): I'd have to generate the bindings to test it myself, which I can't do at ths time.Last edit: Peter A. Bigot 2016-09-27
There is an inertia (non-global) nested inside inertial (global). So, am I correct that I have to use BIND to fill it?
OK, I'm back and have been able to play with that schema.
Whoever coded that schema appears be unfamiliar with how XML schema work. While it does accept the set of documents it's probably intended to accept, it also accepts an infinite number of unlikely documents because of the use of
choicewheresequenceorallwould be far more appropriate.For completeness, starting with bindings generated with this command:
I used the attached program to verify that the following document is valid:
It's acceptable because although the innermost
choicemodel groups produce either zero or one element (i.e. the element is optional), they are all contained inchoicemodel groups that require one or more of any alternative.The use of an outer unbounded
choicemodel group means that every element can appear multiple times; in PyXB terms that the elements are plural. Thus they are represented by lists, not instances of types. APyXB.BINDinstance is compatible only with instances of types.So you can construct instances using the following code which is part of the
i.pyprogram attached:In example that I've also shown how to display the reason why an element is invalid, which provides further clues on how to fill it in:
Last edit: Peter A. Bigot 2016-09-29