views:

27

answers:

1

Assume there exists an XML instance document that looks like this:

<root>
    <object type="foo">
        <!-- ... -->
    </object>

    <object type="bar">
        <!-- ... -->
    </object>
</root>

My goal is to have a small (static) schema that verifies proper <element type="xxx" /> syntax for objects, and another schema (more prone to change) that verifies the contents of each object element against a complexType that matches the type attribute:

<complexType name="foo"><!--should match object with type="foo"--></complexType>
<complexType name="bar"><!--should match object with type="bar"--></complexType>

What is the best way to accomplish this (or something similar)?

+1  A: 

There's no way to do this with pure XML Schema.

You could validate using the "static" schema, then for each element, validate it against the specific complexType that it should match, not against the entire schema.

John Saunders
Not the answer I was hoping for, but thanks!
Joshua Johnson