[xsd-users] Bug with groups and occurence

Boris Kolpackov boris at codesynthesis.com
Wed Mar 21 09:34:22 EDT 2007


Hi Bram,

Bram De Wachter <bdewacht at gmail.com> writes:

> Et voilà, XSD tree 2.3.1 generates the BinaryOperatorType class with
> only (!!!) containers (!!!) for all possible operators (unary/binary).
> So it is impossible to find out the sequence in which the operands
> appear.
>
> Example:
>
> <Expression>
>  <Div>
>    <Constant>5</Constant>
>    <Sum>
>      <Constant>2</Constant>
>      <Constant>1</Constant>
>    </Sum>
>  </Div>
> </Expression>
>
> 1/ There is no way to find out if the sum comes before the Constant 5
> or the other way around.


We made a choice to go with a flattened structure, one side-effect
of which is the loss of ordering information in some cases. You can
read more about this trade-off in the recent thread titled "<choice>
abuse", particularly this post:

http://codesynthesis.com/pipermail/xsd-users/2007-March/000863.html

To be able to preserve ordering information, we would have to resort
to a single sequence that contains all sub-elements. Since such a
container would need to store elements of different types, it would
need to store a pointer to some base type which you would have to
dynamic_cast to figure out what each element actually is (.e.g., is
it a Constant, or a Sum, or a Div?). I think by now you realize that
such a structure would look a lot like DOM.

One way to work around this problem would be to use the DOM
association feature. It allows you to keep an association between
DOM nodes and Tree nodes and to get from Tree node to a DOM and
back. So, in your case, you would handle the above example like
this:

1. Get to the Div Tree node
2. Get a DOMElement instance corresponding to Div
3. Iterate over Div DOMElement's sub-elements in the order of
   appearance.
4. From each sub-element DOMElement get back to the Tree node
   (Constant and Sum in the example above).

For more information on this feature see the 'mixed' example
as well as the C++/Tree mapping manual.

Alternatively, if you can change your XML, then you could
establish explicit ordering, for example:

<Div>

  <Arg>
    <Constant>5</Constant>
  </Arg>

  <Arg>
    <Sum>
      <Arg>
        <Constant>2</Constant>
      </Arg>

      <Arg>
        <Constant>1</Constant>
      </Arg>
    </Sum>
  </Arg>
</Div>



> 2/ Also, it is not clear to me how both Constants (1 and 2) are
> inserted in a single container.

They are inserted in the order of appearance in the XML instance.


hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20070321/c03fb2ea/attachment.pgp


More information about the xsd-users mailing list