XML模式和实例错误

时间:2013-04-17 13:31:58

标签: xml

我尝试以下xml架构

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://your_namespace"
        xmlns="http://your_namespace">
    <xsd:element name="person">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="firstname" type="xsd:string"/>
                <xsd:element name="lastname" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

我将其分配给本文件

<?xml version="1.0"?>
<person xmlns="http://your_namespace"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://your_namespace
                C:\Program%20Files%20(x86)\Wattle%20Software\XMLwriter%202\Projects\ex.xsd">
    <firstname>aaa</firstname>
    <lastname>bbb</lastname>
</person>

但我总是因意外的元素名字

而出错

1 个答案:

答案 0 :(得分:1)

请参阅this重复的问题。您需要添加elementFormDefault =“qualified”:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
        targetNamespace="http://your_namespace"
        xmlns="http://your_namespace">
    <xsd:element name="person">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="firstname" type="xsd:string"/>
                <xsd:element name="lastname" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>