我是XML的初学者。 我创建了一个XSD和另一个XML文件来检查一些验证。检查验证后,它会提示错误消息,我无法修复它。
---在我创建的XSD下面
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Employee"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EmployeeType">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Address" type="xs:string"
minOccurs="1" maxOccurs="unbounded" />
<xs:element name="Phone" type="xs:string"
minOccurs="1" maxOccurs="3" />
<xs:element name="DateOfBirth" type="xs:date" />
</xs:sequence>
<xs:attribute name="Empno" type="xs:integer" />
</xs:complexType>
<xs:complexType name="Employees">
<xs:sequence>
<xs:element name="Employee" type="EmployeeType"
minOccurs="0" maxOccurs="4" />
</xs:sequence>
</xs:complexType>
</xs:schema>
- 这是我输入的数据XML
<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee Empono ="001">
<Name>Alex</Name>
<Adress>Florida</Adress>
<Phone>1234567890</Phone>
<DateOfBirth>10-09-1991</DateOfBirth>
</Employee>
<Employee Empono ="002">
<Name>Lynda</Name>
<Adress>Florida</Adress>
<Phone>1234567890</Phone>
<DateOfBirth>1-12-1991</DateOfBirth>
</Employee>
</Employees>
验证后提示我这条消息:(
无法找到元素'Employees'的声明。
答案 0 :(得分:0)
您需要将<xs:element>
标记作为最外层的包装,它定义<Employees>
标记:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Employee" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EmployeeType">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Address" type="xs:string" minOccurs="1"
maxOccurs="unbounded" />
<xs:element name="Phone" type="xs:string" minOccurs="1"
maxOccurs="3" />
<xs:element name="DateOfBirth" type="xs:date" />
</xs:sequence>
<xs:attribute name="Empno" type="xs:integer" />
</xs:complexType>
<xs:element name="Employees">
<xs:complexType name="EmployeesType">
<xs:sequence>
<xs:element name="Employee" type="EmployeeType" minOccurs="0"
maxOccurs="4" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>