XSD 在同一个文件中使用定义的复杂类型

XSD using defined complex type within same file

我有以下 XSD 文件(相关位):

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://somenamespace"
        elementFormDefault="qualified">

    <complexType name="UserType">
        <sequence>
            <element name="id" type="int" minOccurs="0" maxOccurs="1"/>
            <element name="registrationDate" type="date" minOccurs="0" maxOccurs="1"/>
            <element name="email" type="string" minOccurs="0" maxOccurs="1"/>
            <element name="name" type="string" minOccurs="0" maxOccurs="1"/>
            <element name="surname" type="string" minOccurs="0" maxOccurs="1"/>
        </sequence>
    </complexType>

    <complexType name="UserListType">
        <sequence>
            <element name="userList" type="tns:UserType" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
    </complexType>

</schema>

我遇到的问题是这无效。当我尝试在线验证 XSD 时出现此错误:Cannot resolve tns:UserType as a QName, the prefix tns is not declared.

据我所知,tns 指的是 "this namespace",我需要在这里使用它,因为我已经将全局命名空间定义为模式标记中的 XMLSchema。这一定是一些小疏忽,我对此很陌生。

据我所知,w3c 模式中没有任何预定义的 tns 命名空间,因此您必须将 xmlns:tns="http://somenamespace" 添加到您的模式标记中。