[xsd-users] Re: In-memory validation

Boris Kolpackov boris at codesynthesis.com
Wed Sep 26 08:33:33 EDT 2007


Hi David,

david.r.moss at selex-comms.com <david.r.moss at selex-comms.com> writes:

> // Load will fail when content is invalid.
> auto_ptr<memory_test_t> rt( root( "in-memory-validation-test.xml" ) );
>
> // Modify with a valid value (range is 20-80 inclusive).
> rt->bounded_int( 50 );
> cout << *rt << endl;
>
> rt->bounded_int( 100 ); // Ideally, this should fail (throw exception - as
> initial file load would)
> cout << *rt << endl;
>
> I believe this kind of capability was on your 'to do' list at one point;
> is this still the case and, if so, do you have an idea of time-scales?!

The plan has evolved a bit over time. The main problem with the in-
memory validation is that the mapping of the XML Schema model to
object model as implemented in C++/Tree will not allow certain kinds
of structure validation that can be found in schema definitions.
Without going into much detail, consider the following schema
fragment:

<complexType name="A">
  <sequence maxOccurs="unbounded">
    <element name="s" type="string"/>
    <choice>
      <element name="x" type="int"/>
      <element name="y" type="int"/>
    </choice>
  </sequence>
</complexType>

The C++/Tree mapping maps the there elements in the above construct
to three independent sequences. It will be next to impossible to make
sure the content in the object model matches the structure in the above
schema. Note that this "loose" mapping is a trade-off between ease of
use and exact content representation that we feel is preferable in most
use-cases (most users don't want an object model that is as hard to use
as DOM).

As a result, the current plan is as follows:

1. Implement a subset of XML Schema validation in C++/Tree. The feature
   that we plan to support are for datatype-related validation (e.g.,
   facets, etc.). The nice thing about this types of checks is that
   they are cheap, fast and allow instant error detection, as you have
   shown in your example above.

2. We are also working on another in-memory (or more precisely, hybrid
   in-memory/even-driven) mapping that will be more "low-level" compared
   to C++/Tree. It will support high-performance XML Schema structure
   and datatype validation during both parsing and serialization.


Note also that for (1), some check are already supported in the generated
code. For example enumeration facets are enforced for string-based types.
The other checks will be implemented as requested by the users. So it would
be helpful if you could provide me with a list XML Schema constructs that
you would like validated in the generated code. We probably can support
some of them for the next release of XSD.

There is no definite time-frame for (2). The current plan is to release it
some time in the first quarter of 2008.


Boris




More information about the xsd-users mailing list