tags:

views:

241

answers:

2

I have this xsd:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://myschema.com/schema"
           targetNamespace="http://myschema.com/schema"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xs:complexType name="aType" mixed="true">
        <xs:group ref="aElements" minOccurs="0" maxOccurs="unbounded"/>
    </xs:complexType>

    <xs:group name="aElements">
        <xs:choice>
            <xs:element name="a" type="aType"/>
        </xs:choice>
    </xs:group>

    <xs:element name="b">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:group ref="aElements"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>

and I try to validate this xml document against it:

<?xml version="1.0" encoding="utf-8" ?>
<b xmlns="http://myschema.com/schema"&gt;
    <a/>
</b>

However, Visual Studio 2008's xml validator complains about the <a> element:

The element 'b' in namespace 'http://myschema.com/schema' has invalid child element 'a' in namespace 'http://myschema.com/schema'. List of possible elements expected: 'a'.

What is the problem?

Edit: Oops, when dumbing down the example I caused forgot to make the element optional inside the element, causing infinite recursion. The problem is still there with this mod, though.


ANSWER: The answer was that the xs:schema tag should include the elementFormDefault="qualified" attribute.

A: 

you define aElements with aType, and aType with aElements. i'm not an xsd expert, but how is that supposed to work?

ax
Oops, the element was meant to be optioal. Q updated.
erikkallen
A: 

You could make your life much easier using an editor for XSD development. We've been using Liquid XML Studio for ages, it makes life much easer.

Colin
not an answer to the question
Ilja Preuß