我是XML和Schema的新手,我很难尝试验证我的文档。我一直在第13行第58栏中得到元素声明内容必须匹配的错误。我已经尝试了所有我能想到的内容,并阅读了每篇文章和其他问题,但无法弄清楚。请帮忙!
这是我的XML:
<?xml version="1.0" encoding="UTF-8" ?>
<CustomerAccount xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" LastUpdated="2011-12-01" xsi:noNamespaceSchemaLocation="me.xsd">
<UpdatedBy kind="SalesPerson">Lisa Moroz</UpdatedBy>
<ShipTo country="Canada">
<name>Maya Wells</name>
<street>44 Gamble Avenue</street>
<city>Toronto</city>
<province>ON</province>
<zip>L1M3G1</zip>
</ShipTo>
<ShipTo country="Canada">
<name>Maya Wells</name>
<street>62 Elm Street</street>
<city>Montreal</city>
<province>QC</province>
<zip>K2J3H4</zip>
</ShipTo>
<BillTo>
<country>Canada</country>
<name>Maya Wells</name>
<street>78 Audley Street</street>
<city>Oakville</city>
<province>ON</province>
<zip>O3R1M5</zip>
</BillTo>
</CustomerAccount>
这是我的架构:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="CustomerAccount">
<xs:complexType>
<xs:sequence>
<xs:simpleType>
<xs:element name="UpdatedBy" type="xs:string" />
</xs:simpleType>
<xs:sequence>
<xs:element name="ShipTo" type="ShipToType" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="BillTo" type="BillToType" />
</xs:sequence>
<xs:attribute name ="kind" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ShipToType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="province" type="xs:string"/>
<xs:element name="zip" type="xs:string"/>
</xs:sequence>
<xs:attribute name="country" type="xs:string"/>
</xs:complexType>
<xs:complexType name="BillToType">
<xs:sequence>
<xs:element name="country" type="xs:string" />
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="province" type="xs:string"/>
<xs:element name="zip" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
感谢您的帮助!
答案 0 :(得分:0)
我认为应该以这样的方式修改CustomerAccount
元素定义:
<xs:element name="CustomerAccount">
<xs:complexType>
<xs:sequence>
<xs:element name="UpdatedBy">
<xs:complexType mixed="true">
<xs:attribute name ="kind" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="ShipTo" type="ShipToType" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="BillTo" type="BillToType" />
</xs:sequence>
<xs:attribute name="LastUpdated" type="xs:date"></xs:attribute>
</xs:complexType>
</xs:element>