2

The following XML with XSD causes the validation error:

The element 'choices' in namespace 'http://www.test.it' has invalid child element 'choice' in namespace 'http://www.test.it'. List of possible elements expected: 'choice'.

This is choices.xml:

<?xml version="1.0" encoding="utf-8"?>
<choices xmlns="http://www.test.it"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
         xsd:schemaLocation="http://www.test.it ./schema/choices.xsd">
    <choice>yes</choice>
</choices>

This is schema/choices.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema  xmlns="http://www.test.it"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.test.it">

    <xs:simpleType name="yes_or_no_t">
        <xs:restriction base="xs:string">
            <xs:enumeration value="yes" />
            <xs:enumeration value="no" />
        </xs:restriction>
    </xs:simpleType>

    <xs:element name="choices" >
        <xs:complexType>
            <xs:all>
                <xs:element name="choice" type="yes_or_no_t" />
            </xs:all>
        </xs:complexType>
    </xs:element>

</xs:schema>

I must keep the xmlns="http://www.test.it" in the XML. The XML and XSD are meant to be local files (not published via network). I would rather keep the XSDs in a schema subdirectory.

0

1 Answer 1

1

There were two problems...

Finding the XSD

Use xsi:schemaLocation for namespaced XML such as yours, not xsi:noNamespaceSchemaLocation.

See also:

Qualified elements

Add elementFormDefault="qualified" to the schema element of your XSD.

See also:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.