You cannot dynamically populate a schema while parsing (also because
when you get the notification of an element, that element has already
been validated); I would just build a big schema with the definitions
for the all the possible objects, with a definition for the root element
that allows any number of them (e.g. <xs:any namespace="##local"
maxOccurs="unbounded"/>)
Alberto
Johan Ditmar wrote:
Hi,
I am using Xerces-C++ to parse an XML document into a hierarchical object
structure. There are many different types of objects in this structure, each
corresponding to different XML, and I would like to use schema validation.
As I need to be able to parse any object structure, I can't use a fixed schema
that I know beforehand. Instead I would like to parse the XML, and when I
encounter the start of an object, I would like to dynamically load the schema
that is unique for that object and continue parsing and validating the child
elements of that object.
For example, my XML could look as follows:
...
<parent type="ObjA">
<child1 type="ObjB">
<name>Some Name</name>
</child1>
<child2 type="ObjC">
<value>Some Value</value>
</child2>
</parent>
Here, when I encounter ObjA during parsing, I want to load the schema of Obj1,
which validates that there should be two sub-elements, child1 and child2. And
this should be repeated for ObjB and ObjC.
The only way I can see this work at the moment is by parsing the structure
twice: once without validation to find all the objects and assemble the schema,
and once with validation. But I was wondering whether this can be done in one
pass. Any ideas?
Johan
__________________________________________________________
Not happy with your email address?.
Get the one you really want - millions of new email addresses available now at
Yahoo! http://uk.docs.yahoo.com/ymail/new.html