Menu

Anonymous context type

Help
Esteve
2016-09-27
2016-09-28
  • Esteve

    Esteve - 2016-09-27

    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

     
  • Peter A. Bigot

    Peter A. Bigot - 2016-09-27

    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...).

    Please review the examples and discussion here.

     
  • Esteve

    Esteve - 2016-09-27

    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).

     
  • Peter A. Bigot

    Peter A. Bigot - 2016-09-27

    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
  • Esteve

    Esteve - 2016-09-28

    There is an inertia (non-global) nested inside inertial (global). So, am I correct that I have to use BIND to fill it?

     
  • Peter A. Bigot

    Peter A. Bigot - 2016-09-28

    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:

    pyxbgen -u http://sdformat.org/schemas/root.xsd -m sdf
    

    I used the attached program to verify that the following document is valid:

    <?xml version="1.0" ?>
    <inertial>
        <inertia>
            <ixx>1.0</ixx>
            <ixx>2.0</ixx>
            <ixx>3.0</ixx>
        </inertia>
        <inertia>
            <ixx>0.0</ixx>
        </inertia>
    </inertial>
    

    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:

    x = sdf.inertial()
    x.inertia = [pyxb.BIND()];
    try:
        x.validateBinding()
    except pyxb.ValidationError as e:
        print(e.details())
    x.inertia[0].ixx = [pyxb.BIND(1)];
    x.inertia[0].ixy = [pyxb.BIND(2)];
    print(x.toDOM().toprettyxml())
    

    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:

    The containing element type <class 'sdf.CTD_ANON_54'> is defined at inertial.xsd[37:10]
    The <class 'sdf.CTD_ANON_54'> automaton is not in an accepting state.
    No content has been accepted
    The following element and wildcard content would be accepted:
        An element ixx per inertial.xsd[40:14]
        An element ixy per inertial.xsd[44:14]
        An element ixz per inertial.xsd[48:14]
        An element iyy per inertial.xsd[52:14]
        An element iyz per inertial.xsd[56:14]
        An element izz per inertial.xsd[60:14]
    No content remains unconsumed
    
     

    Last edit: Peter A. Bigot 2016-09-29

Log in to post a comment.

MongoDB Logo MongoDB