map xml element to xsd complexType based on attribute

Posted by Joshua Johnson on Stack Overflow See other posts from Stack Overflow or by Joshua Johnson
Published on 2010-06-14T01:24:30Z Indexed on 2010/06/14 1:32 UTC
Read the original article Hit count: 392

Filed under:
|
|

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)?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xsd