【问题标题】:Validate xsd against xml根据 xml 验证 xsd
【发布时间】:2014-08-15 11:53:24
【问题描述】:

我刚学完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>

我的 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>

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

现在该怎么办?

【问题讨论】:

  • "我刚学完xml和xsd"。哦亲爱的。在我看来,你好像刚刚开始......

标签: xml xsd


【解决方案1】:
<?xml vesion="1.0"

应该是

<?xml version="1.0"

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

xmlns:xs="http://WWW.W3.org/2001/XMLSchema"

需要改成

xmlns:xs="http://www.w3.org/2001/XMLSchema"

【讨论】:

    猜你喜欢
    • 2016-07-09
    • 1970-01-01
    • 2016-10-19
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 2012-05-13
    相关资源
    最近更新 更多