Menu

Validation Bug

Help
2016-11-02
2016-11-04
  • Arindam Roy

    Arindam Roy - 2016-11-02

    Hello,

    Given below is a simplified version of a schema I am using.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:complexType name="EarlyTerminationProvision">
            <xsd:group ref="OptionalEarlyTermination.model"/>
        </xsd:complexType>
        <xsd:group name="OptionalEarlyTermination.model">
            <xsd:choice>
                <xsd:element name="optionalEarlyTermination"/>
                <xsd:sequence>
                    <xsd:element name="optionalEarlyTerminationParameters"/>
                    <xsd:element name="optionalEarlyTermination" minOccurs="0"/>
                </xsd:sequence>
            </xsd:choice>
        </xsd:group>
    </xsd:schema>
    

    The design choice of the schema is admitted slightly unusual. Unfortunately I do not have powers to change the design.

    Given the schema I am trying to generate a document like the below:

    <?xml version="1.0" ?>
    <earlyTermination>
    <optionalEarlyTerminationParameters>Foo</optionalEarlyTerminationParameters>
        <optionalEarlyTermination>Bar</optionalEarlyTermination>
    </earlyTermination>
    

    Assuming that pyxb generate are stored in a module called mybindings, I am doing the following:

    >>> elem = mybinding.EarlyTerminationProvision()
    >>> elem.optionalEarlyTerminationParameters = 'Foo'
    >>> elem.optionalEarlyTermination = 'Bar'
    >>> elem.toxml( element_name='earlyTermination' )
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "ext2\noarch\pylib\site-packages\pyxb\binding\basis.py", line 541, in toxml
      File "ext2\noarch\pylib\site-packages\pyxb\binding\basis.py", line 513, in toDOM
      File "ext2\noarch\pylib\site-packages\pyxb\binding\basis.py", line 2647, in _toDOM_csc
      File "ext2\noarch\pylib\site-packages\pyxb\binding\basis.py", line 2174, in _validatedChildren
      File "ext2\noarch\pylib\site-packages\pyxb\binding\content.py", line 640, in sequencedChildren
    UnprocessedElementContentError: (<mybindings.EarlyTerminationProvision object at 0x2FE87450>, <pyxb.utils.fac.Configuration object at 0x2FE87510>, [<pyxb.binding.basis.ElementContent object at 0x2FE87E70>], {<pyxb.binding.content.ElementDeclaration object at 0x2FEBBD10>: [<pyxb.binding.datatypes.anyType object at 0x2FE87110>]})
    
    >>> try:
    ...     elem.toxml( element_name='earlyTermination' )
    ... except Exception as e:
    ...     print e.details()
    ...     
    The containing element type EarlyTerminationProvision is defined at <unknown>[3:4]
    The EarlyTerminationProvision automaton is in an accepting state.
    The last accepted content was optionalEarlyTermination
    No elements or wildcards would be accepted at this point.
    The following content was not processed by the automaton:
        optionalEarlyTerminationParameters (1 instances)
    

    I presume this issue is linked to this statement in this document:

    As of PyXB 1.2.0 the first legal transition in the order imposed by the schema is taken, and there is no provision for influencing the order in the generated document when multiple orderings are valid.

    Is there a work around for this issue?

    Regards
    Arindam

     

    Last edit: Arindam Roy 2016-11-02
  • Peter A. Bigot

    Peter A. Bigot - 2016-11-02

    In fact, yes. Take a look at this description and this source file.

    For your example, adding the following commands before generating the XML seems to make it work:

    import pyxb
    pyxb.GlobalValidationConfig._setContentInfluencesGeneration(pyxb.ValidationConfig.ALWAYS);
    
     
    • Guillaume Humbert

      Post awaiting moderation.
  • Arindam Roy

    Arindam Roy - 2016-11-03

    That works indeed. Many thanks, much appretiate the help!!!

     
  • Guillaume Humbert

    Post awaiting moderation.
  • Peter A. Bigot

    Peter A. Bigot - 2016-11-04

    The command I gave specifies that the orderedContent order is to be used. I suspect that creating the instance with keyword arguments puts the content in a different order. There is no solution for that other than changing the schema, or modifying the orderedContent array.

     

Log in to post a comment.