|
图 9. 以属性为中心的映射
XML 实例
<?xml version="1.0"?> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Employees EmployeeId="1" FirstName="Janet" LastName="Leverling" Title="Sales Representative"/> <Employees EmployeeId="2" FirstName="Nancy" LastName="Davolio" Title="Technical Advisor"/> <Employees EmployeeId="3" FirstName="Robert" LastName="Fuller" Title="Accountant"/> </Root>
XSD
<?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="Root"> <complexType> <sequence> <element name="Employees" maxOccurs="unbounded"> <complexType> <attribute name="EmployeeId" type="positiveInteger"/> <attribute name="FirstName" type="string"/> <attribute name="LastName" type="string"/> <attribute name="Title"> <simpleType> <restriction base="string"> <enumeration value="Sales Representative"/> <enumeration value="Technical Advisor"/> <enumeration value="Accountant"/> </restriction> </simpleType> </attribute> </complexType> </element> </sequence> </complexType> </element> </schema>
显然,有像架构一样尽可能多的格式来创建它们。这里介绍这组格式化可能性的目的是,为您开发和精细调整您自己的架构提供一个起点。小结
架构使您能够指定哪些元素、属性、数据类型和层次结构允许在 XML 数据文件中出现。您可以使用架构文件验证 XML 数据,并在交换数据时
确保可预见性。由于该可预见性,您可以调整您的架构来确保数据可以正确显示。在 Excel 中,您使用 XML Source 任务网格将元素映射到
单元格。然后,将 XML 数据导入到一个最适合您需要的窗体是相对较容易的。
|