简体   繁体   中英

Element type “xs:schema” must be followed by either attribute specifications, “>” or “/>” - XML schema design validation failing

I have the following XSD file. It's showing me an error message

Element type "xs:schema" must be followed by either attribute specifications, ">" or "/>"

I have already checked all opening and closing tags. Not able to figure the issue. I have taken this code from here . What is the issue with <xs:schema> tag ?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
    xmlns:ms="http://codereq.com/mathservice/schemas"   elementFormDefault="qualified"  
    targetNamespace="http://codereq.com/mathservice/schemas">
        
    <element name="MathServiceRequest">
                
        <complexType>
        <sequence>
            <element name="Number" type="xs:integer"/>
        </sequence>
    </complexType>
    </element>
    <element name="MathServiceResponse">
        
        <complexType>
        <sequence>
            <element name="Number" type="xs:integer" />
            <element name="isEven" type="xs:boolean" />
        </sequence>
    </complexType>
    </element>
</xs:schema>

The child elements in your XSD do not belong to the correct namespace. You must prefix them with the same prefix you used for the <xs:schema> element in xmlns:xs="http://www.w3.org/2001/XMLSchema" :

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
    xmlns:ms="http://codereq.com/mathservice/schemas"   
    elementFormDefault="qualified"  
    targetNamespace="http://codereq.com/mathservice/schemas">

    <xs:element name="MathServiceRequest">

        <xs:complexType>
            <xs:sequence>
                <xs:element name="Number" type="xs:integer"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="MathServiceResponse">

        <xs:complexType>
            <xs:sequence>
                <xs:element name="Number" type="xs:integer" />
                <xs:element name="isEven" type="xs:boolean" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

That strange error message is possibly because your types were prefixed, and valid XSD types, but the elements were not. Normally the validator would complain with a different message such as:

Element element cannot appear here: expected one of (element, attribute, complexType, ...)

which still seems confusing (since there is no mention to the missing namespace prefix), but less obscure.

Note : you actually could have unprefixed elements in the schema, as long as the XSD namespace is the default namespace using xmlns="http://www.w3.org/2001/XMLSchema" :

<schema xmlns="http://www.w3.org/2001/XMLSchema"  
    xmlns:ms="http://codereq.com/mathservice/schemas" 
    elementFormDefault="qualified"  
    targetNamespace="http://codereq.com/mathservice/schemas">

   <element name="MathServiceRequest">      
        <complexType>
            <sequence>
                <element name="Number" type="xs:integer"/>
            </sequence>
        </complexType>
    </element>
    <element name="MathServiceResponse">
        <complexType>
            <sequence>
                <element name="Number" type="xs:integer" />
                <element name="isEven" type="xs:boolean" />
            </sequence>
        </complexType>
    </element>
</schema>

This would be OK in your case because the target namespace xmlns:ms="http://codereq.com/mathservice/schemas" is mapped to a prefix (instead of using the default namespace, which is usual).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM