根据 xml 验证 xsd

use*_*604 6 xml xsd

我刚刚学完xml和xsd。我制作了第一个 xml 文档,我只是想确保我使用 xsd 正确验证它。

我的xml代码:

<?xml version="1.0" encoding="UTF-8" ?>
<user xmlns="http://localhost" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost user.xsd">
<name>
    <first>jack</first>
    <last>hals</last>
</name>
<name>
    <first>harry</first>
    <last>potter</last>
</name>
</user>
Run Code Online (Sandbox Code Playgroud)

我的 xsd 代码:

<?xml vesion="1.0" encoding="UTF-8" ?><xs:schema xmlns:xs="http://WWW.W3.org/2001/XMLSchema" targetNamespace="http://localhost" xmlns="http://localhost" elementFormDefault="qualified">
<xs:element name="user" block="substitution" minOccurs="1" maxOccurs="1">
<xs:complexType>
    <xs:sequence>
        <xs:element name="name" minOccurs="1" maxOccurs="5" block="substitution">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="first" type="xs:string" default="jack" minOccurs="1" maxOccurs="1" block="substitution" />
                    <xs:element name="last" type="xs:string" default="hals" minOccurs="1" maxOccurs="1" block="substitution" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

我尝试过在线验证器,它说:A pseudo attribute name is expected.

现在做什么?

Ian*_*rts 8

<?xml vesion="1.0"
Run Code Online (Sandbox Code Playgroud)

应该

<?xml version="1.0"
Run Code Online (Sandbox Code Playgroud)

(你错过了一个“r”)。此外,命名空间 URI 区分大小写,因此

xmlns:xs="http://WWW.W3.org/2001/XMLSchema"
Run Code Online (Sandbox Code Playgroud)

需要更改为

xmlns:xs="http://www.w3.org/2001/XMLSchema"
Run Code Online (Sandbox Code Playgroud)