Non-Deterministic error in an if-else xml block

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tangleman
    New Member
    • Oct 2008
    • 6

    Non-Deterministic error in an if-else xml block

    I have a schema that defines a programming language for a script that drives a sequentially executing process. It defines the structure of a script that has to interact with a pre-existing, custom-made XML parsing engine. Part of this is an if-else block that has to be defined as:

    <if {condition}>
    statements...
    <else/>
    statements...
    </if>

    The else and subsequent statements are optional. Also, the statements after else can be any of the statements before else.

    This is how I have it defined in the schema:

    <xs:element name="if">
    <xs:complexType >
    <xs:sequence>
    <xs:choice minOccurs="0" maxOccurs="unbo unded">
    <xs:group ref="general_co mmand"/>
    <xs:group ref="macro_cont rol_command"/>
    </xs:choice>
    <xs:element ref="else" minOccurs="0"/>
    <xs:choice minOccurs="0" maxOccurs="unbo unded">
    <xs:group ref="general_co mmand"/>
    <xs:group ref="macro_cont rol_command"/>
    </xs:choice>
    </xs:sequence>
    </xs:complexType>
    </xs:element

    When I try to validate, XMLSPY reports a non-deterministic error, which I believe is because general_command and macro_control_c ommand are reqeated in the same element. I'm wondering if there is any way to get around this error so that the schema will validate, without giving up the structure/functionality that I need?

    Thanks!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    do you get the same error when you define only one unique <xs:group> per <xs:element>?
    are there any elements in both groups?

    Comment

    • Tangleman
      New Member
      • Oct 2008
      • 6

      #3
      You mean like this?

      <xs:element name="if">
      <xs:complexType >
      <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbo unded">
      <xs:group ref="general_co mmand"/>
      <xs:group ref="macro_cont rol_command"/>
      </xs:choice>
      <xs:element ref="else" minOccurs="0"/>
      </xs:sequence>
      </xs:complexType>
      </xs:element>

      This does work without errors, but it takes away the functionality that I'm looking for. It turns this:

      if
      statements
      else
      statements
      end if

      into this:

      if
      statements
      else
      end if

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Put a sequence around the second part of the statement. Make this optional, and the else part required, with respect to the optional sequence.
        [code=xml]
        <xs:element name="if">
        <xs:complexType >
        <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbo unded">
        <xs:group ref="general_co mmand"/>
        <xs:group ref="macro_cont rol_command"/>
        </xs:choice>
        <xs:sequence minOccurs="0">
        <xs:element ref="else"/>
        <xs:choice minOccurs="0" maxOccurs="unbo unded">
        <xs:group ref="general_co mmand"/>
        <xs:group ref="macro_cont rol_command"/>
        </xs:choice>
        </xs:sequence>
        </xs:sequence>
        </xs:complexType>
        </xs:element>
        [/code]

        ---
        Just to explain the error:
        You had it written as:
        A. If
        B. Stmts (optional)
        C. Else (optional)
        D. Stmts (optional).


        So if we had

        If
        Stmts.

        Does the parser parse the stmts as coming from block B, or block D? It can't tell so the parser craps out.

        Comment

        • Tangleman
          New Member
          • Oct 2008
          • 6

          #5
          Worked like a charm!

          Thanks a lot jkmyoung!!

          Comment

          Working...