简体   繁体   中英

S4s-att-not-allowed: Attribute 'targetNameSpace' Cannot Appear In Element 'schema' validation error

So I get this error when attempting to validate my XML

"S4s-att-not-allowed: Attribute 'targetNameSpace' Cannot Appear In Element 'schema'."

I have a commonTypes.xsd with all the rules that I would need to associate to different elements. This is the commonTypes.xsd file:

  <?xml version="1.0" encoding="utf-16" ?>
<xs:schema
           targetNamespace="common"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified">

<!-- Password Restrictions -->
    <xs:simpleType name="passWord">
        <xs:restriction base="xu:string">
            <xs:pattern value="[A-Za-z0-9_]{6,12}" />
        </xs:restriction>
    </xs:simpleType>

    <!-- User Name Restrictions -->
    <xs:simpleType name="userName">
        <xs:restriction base="xu:string">
            <xs:pattern value="[A-Za-z]{6,12}" />
        </xs:restriction>
    </xs:simpleType>

    <!-- Name Retrictions -->
    <xs:simpleType name="firstName">
        <xs:restriction base="xu:string">
            <xs:pattern value="[A-Za-z]" />
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="middleName">
        <xs:restriction base="xu:string">
            <xs:pattern value="[A-Za-z]" />
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="lastName">
        <xs:restriction base="xu:string">
            <xs:pattern value="[A-Za-z]" />
        </xs:restriction>
    </xs:simpleType>

    <!-- Email Restrictions -->
    <xs:simpleType name="email">
        <xs:restriction base="xu:string">
            <xs:pattern value="[^@]+@[^\.]+\..+" />
        </xs:restriction>
    </xs:simpleType>

    <!-- Gender -->
    <xs:simpleType name="gender">
        <xs:restriction base="xu:string">
            <xs:pattern value="male|female" />
        </xs:restriction>
    </xs:simpleType>

    <!-- Number Restrictions -->
    <xs:simpleType name="number">
        <xs:restriction base="xu:integer">
            <xs:pattern value="^[2-9]\d{2}-\d{3}-\d{4}$" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

the file that I am attempting to validate- and its schema are as follows:

user.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<user xmlns="localhost"
      xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
    >
<!-- I will use xs:schemalocation="/user.xsd" as the location of the schema -->
    <userId></userId>
    <loginInfo>
        <userName></userName>
        <passWord></passWord>
    </loginInfo>
    <contactInfo>
        <firstName></firstName>
        <middleName></middleName>
        <lastName></lastName>
    </contactInfo>
    <profile>
        <email></email>
        <dateOfBirth></dateOfBirth>
        <gender></gender>
        <profilePhoto>
        </profilePhoto>
        <homePhone></homePhone>
        <cellPhone></cellPhone>
    </profile>
    <createdDate></createdDate>
</user>

and the user.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:cmn="commonTypes.xsd"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNameSpace="user">
<xs:import namespace="commonTypes" schemaLocation="commonTypes.xsd" />
    <!-- Main Users Schema -->

    <xs:element name="user">
        <xs:complexType>
            <xs:sequence>
        <!-- userID -->
        <xs:element maxOccurs="1" name="userID" type="cmn:ID"/>

        <!-- login Info -->
        <xs:element name="loginInfo">
            <xs:complexType>
                <xs:sequence>
                    <!-- Username and Password -->
                    <xs:element name="userName" type="cmn:userName" />
                    <xs:element name="passWord" type="cmn:passWord" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <!-- Name -->
        <xs:element name="contactInfo">
            <xs:complexType>
                <xs:sequence>
                    <!-- Names -->
                    <xs:element name="firstName" type="cmn:firstName" />
                    <xs:element name="middleName" type="cmn:middleName" />
                    <xs:element name="lastName" type="cmn:lastName" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <!-- Profile -->
        <xs:element name="profile">
            <xs:complexType name="profile">
                <xs:sequence>
                    <!-- Profile -->
                    <xs:element name="email" type="cmn:email" />
                    <xs:element name="dateOfBirth" type="cmn:date" />
                    <xs:element name="gender" type="cmn:gender" />
                    <xs:element name="profilePhoto" type="cmn:image" />
                    <xs:element name="homePhone" type="cmn:number" />
                    <xs:element name="cellPhone" type="cmn:number" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="createdDate" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

So my question is, why I cannot use a targetNameSpace in this schema when I have seen documentation with it being used?

I think this problems stems from me attempting to import- and then use the rules associated with the commonTypes.xsd file.

I am brand new to XML and its kicking my butt. Any other suggestions are welcome. thanks!

The correct spelling is targetNamespace - note the capitalisation.

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