Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Schema: same element name, but different type

Here is an example of the XML I am trying to create a schema for:

...
<tag attr="true">blahblah</tag>
<tag attr="false">blahblah</tag>
<tag attr="true">blahblah</tag>

<tag attr="hello">blahblah</tag>
<tag attr="joe">blahblah</tag>
...

Now here is the problem: These elements belong to the same scope, and when I try to create two different definitions (i.e. 'attr' with boolean; string) for elements of the same name (i.e. 'tag'), like so:

<sequence>
<element name="tag">
<complexType>
<simpleContent>
<extension base="string">
<attribute name="attr" type="boolean" use="required" />
</extension>
</simpleContent>
</complexType>
</element>
<element name="tag">
<complexType>
<simpleContent>
<extension base="string">
<attribute name="attr" type="string" use="required" />
</extension>
</simpleContent>
</complexType>
</element>
</sequence>

... I get a validation error, saying: "In the same scope elements with the same name, [elements] have to be the same type". I have tried many different approaches to solving the problem, such as with 'group', 'union', and 'choice', but I wasn't successful.

Anyone know of a solution to this problem?? (Please keep in mind that I want to have two DIFFERENT definitions, and set these to be the type for elements of the same name, in the same scope.)

Thank you in advance. :)
[1779 byte] By [Jonaed] at [2007-11-11 6:48:56]