<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/book" xmlns:tns="http://www.example.org/book" elementFormDefault="qualified"> <element name="books"> <!--复杂类型 --> <complexType> <!--序列 minOccurs:最少几个,maxOccurs:最多几个 --> <sequence minOccurs="1" maxOccurs="unbounded"> <!--节点 --> <element name="book"> <complexType> <sequence minOccurs="1" maxOccurs="unbounded"> <element name="bookname" type="string"></element> <element name="price" type="int"></element> <!-- 多个选一个 --> <choice> <element name="author" type="string"></element> <element name="authors"> <complexType> <sequence minOccurs="1" maxOccurs="unbounded"> <element name="author" type="string"></element> </sequence> </complexType> </element> </choice> <element name="authorinfo"> <complexType> <!--使用all的话就不用考虑顺序的事情,但是只能出现一次 --> <all> <element name="authorname" type="string"></element> <element name="authorage" type="int"></element> <element name="address" type="string"></element> </all> </complexType> </element> </sequence> <!-- 定义属性,必须在complexType里 且sequence后--> <attribute name="id" type="int" use="required" ></attribute> </complexType> </element> </sequence> </complexType> </element> </schema>