0

XSD 架构说:

Line: 2, Position: 2 "Could not find schema information for the element 'ArrayOfClient'."
Line: 3, Position: 4 "Could not find schema information for the element 'Client'."
Line: 3, Position: 11 "Could not find schema information for the attribute 'ID'."
Line: 3, Position: 27 "Could not find schema information for the attribute 'email'."

XSD 架构:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
    targetNamespace="http://tempuri.org/XMLSchema1.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/XMLSchema1.xsd"
    xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:simpleType name="stringtype">
    <xs:restriction base="xs:string"/>
  </xs:simpleType>

  <xs:complexType name="clientType">
    <xs:attribute name="ID"     type="stringtype" use="required"/>
    <xs:attribute name="email"  type="stringtype" use="required"/>
  </xs:complexType>

  <xs:complexType name="ClientsType">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Client" type="clientType" />
    </xs:sequence>
  </xs:complexType>

  <xs:element name="ArrayOfClient" type="ClientsType"/>
</xs:schema>

XML 文件:

<?xml version="1.0"?>
<ArrayOfClient xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Client ID="00000000" email="user@mail.com" />
</ArrayOfClient>
  1. 这不起作用,xml 文件是使用 .NET C# 中的 XmlSerializer 生成的。
  2. 有没有办法可以对 ID 属性进行验证,使其始终为 10 位数字和电子邮件...?

编辑:有关我在此处构建 XML 文件的方式的更多信息。

4

1 回答 1

1

你错过了应该是的 xmlns http://tempuri.org/XMLSchema1.xsd,即你ArrayOfClient应该有一个属性,例如xmlns="http://tempuri.org/XMLSchema1.xsd"

您指向的示例没有使用 XML 名称空间。我建议简单地运行 xsd.exe /c your.xsd 并查看生成的类。您将确切地看到您缺少哪些差异。

于 2013-10-22T16:05:03.077 回答