schema 简单编写

来源:互联网 发布:招淘宝创业合作伙伴 编辑:程序博客网 时间:2024/05/16 09:40



<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/classroom"xmlns:tns="http://www.example.org/classroom"     elementFormDefault="qualified"><xsd:element name="student" type="tns:studentType"></xsd:element><xsd:complexType name="studentType" >    <xsd:sequence minOccurs="1" maxOccurs="1"><xsd:element name="id" type="tns:stuIdType"></xsd:element><xsd:element name="name" ></xsd:element><xsd:element name="age" type="tns:stuAgeType"></xsd:element><xsd:element name="email" type="tns:stuEmailType"></xsd:element><xsd:element name="sex" type="tns:stuSexType"></xsd:element></xsd:sequence></xsd:complexType><xsd:simpleType name="stuEmailType"><xsd:restriction base="xsd:string"> <xsd:pattern value="\S+@\S+\.\S+" /><xsd:minLength value="5" />  <xsd:maxLength value="20" /></xsd:restriction></xsd:simpleType><xsd:simpleType name="stuSexType"><xsd:restriction base="xsd:string"><xsd:enumeration value="男"/><xsd:enumeration value="女"/></xsd:restriction></xsd:simpleType><xsd:simpleType name="stuIdType"><xsd:restriction base="xsd:int"></xsd:restriction></xsd:simpleType><xsd:simpleType name="stuAgeType"><xsd:restriction base="xsd:int"><xsd:minInclusive value="1"></xsd:minInclusive><xsd:maxInclusive value="150"></xsd:maxInclusive></xsd:restriction></xsd:simpleType></xsd:schema>

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"     targetNamespace="http://www.example.org/classroom"    xmlns:tns="http://www.example.org/classroom"     elementFormDefault="qualified">        <!-- 导入student.xsd文件,前提是两个文件的命名空间要一样 -->    <xsd:include schemaLocation="student.xsd"  />        <xsd:element name="classroom" type="tns:classroomType"></xsd:element>        <xsd:complexType name="classroomType">        <xsd:sequence>            <xsd:element name="id" type="xsd:int"></xsd:element>            <xsd:element name="grade" type="xsd:string"></xsd:element>            <xsd:element name="students">                  <xsd:complexType>                    <xsd:sequence minOccurs="1" maxOccurs="unbounded">                        <xsd:element name="student" type="tns:studentType" />                    </xsd:sequence>                </xsd:complexType>            </xsd:element>        </xsd:sequence>    </xsd:complexType>            </xsd:schema>

<?xml version="1.0" encoding="UTF-8"?><classroom xmlns="http://www.example.org/classroom" ><id>01</id>  <grade>高一3班</grade><students><student><id>01</id><name>is_zhofueng</name><age>19</age><email>is_zhoufeng@163.com</email>  <sex>男</sex>  </student></students></classroom>


可以使用 xjc 命令将xsd文件生成java类

C:\Documents and Settings\zhoufeng>xjc -d d:/01 -verbose D:\zhoufeng\maven_workspace\dtd01\schema02\classroom.xsd