![](/img/trans.png)
[英]XML - XSD validation error: No matching global declaration available for the validation root
[英]global declaration error in XML XSD validation
我是 XML 和 XSD 创建的新手。 我正处于尝试形成验证模式的非常基本的阶段。 但是,我花了很多时间在这个圈子上。 如果有人可以查看并请让我更好地了解代码发生了什么? 就是说根报告没有全局声明。
错误代码读取为
Cvc-elt.1.a:找不到元素“xs:reports”的声明。,“1”行,“134”列。
<?xml version="1.0" encoding="UTF-8"?>
<xs:reports xmlns:xs="https://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="user.xsd">
user(
userID SERIAL,
username varchar(255),
password varchar(255),
firstname varchar(255),
middlename varchar(255),
lastname varchar(255),
email varchar(255),
dob date,
gender varchar(10)
profile_photo bytea,
home_phone varchar(50),
cell_phone varchar(50),
created_date timestamp default current_timestamp
);
</xs:reports>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="reports">
<xs:complexType>
<xs:sequence>
<xs:element name="user">
<xs:complexType>
<xs:sequence>
<xs:element name="userID" type="xs:string"/>
<xs:element name="username" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="middlename" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="dob" type="xs:date"/>
<xs:element name="gender" type="xs:string"/>
<xs:element name="profile_photo" type="xs:string"/>
<xs:element name="cell_phone" type="xs:string"/>
<xs:element name="created_date" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
To remedy your immediate error of failing to associate the XML with an XSD, read How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
然后,在编写 XML 时,实际遵循 XSD:
<reports>
<user>
<userID>123</userID>
<username>John Smith</username>
...
</user>
</reports>
还有一个问题是为什么 XSD 会让user
成为reports
的孩子,但您可以让现有的 XSD 与新的 XML 一起工作作为第一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.