[xsd-users] Re: xsd-users Digest, Vol 35, Issue 9 Re: Code generation fails for schemas with large maxOccurs values (Boris Kolpackov)

Boris Kolpackov boris at codesynthesis.com
Wed May 14 03:22:28 EDT 2008


Hi Gordon, Roger,

Gordon Kramer <gkr at as-guides.com> writes:

> Would it be a big problem to implement code generation for enforcing
> maxOccurs>1 outside xercesc validation ?

While this is definitely an option, I think it is better to fix the bug
in Xerces-C++ since all XML Schema validation (for the C++/Tree mapping)
is done there. Doing some of it in Xerces-C++ and some of it in the
generated code will make it cumbersome to enable/disable validation as
well as report validation errors consistently.

> Maybe adding the maxOccurs constraint as a template parameter to
> sequence ?

Yes, that's probably how I would do it.


> This would also help enforcing the constraint when programatically
> adding elements to the sequence.

This is actually a tricky issue. maxOccurs is one of the few XML
Schema constraints that are natural to enforce immediately (e.g.,
as soon as you've exceeded the limit, you get an exception). Its
sibling, minOccurs, does not have this property: we don't want
an exception thrown for creating an empty sequence which we plan
on populating in the next line.

If we enforce maxOccurs in the generated code then it would be
natural for the user to expect that minOccurs is also somehow
enforced. Because of this we have refrained from enforcing any
XML Schema constraints in the generated code other than through
the interface. For more information on this you may also want to
check the following discussion:

http://www.codesynthesis.com/pipermail/xsd-users/2008-January/001443.html


Roger Evans <roger at autodata.no> writes:

> And enforced fixed attributes, too - while you're at it :)

This can actually be easily done through the interface by not generating
the modifiers. I think it hasn't been done yet because not many people
use fixed attributes. I've added this to the 3.2.0 TODO list.

Thanks,
Boris




More information about the xsd-users mailing list