java学习

java学习

 

schema的笔记


schema文件:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.org/01"
  xmlns:tns="http://www.example.org/01"
  elementFormDefault="qualified">
 <element name="user">
  <complexType>
   <sequence>
    <element name="id" type="int"/>
    <element name="username" type="string"/>
    <element name="born" type="date"/>
   </sequence>
  </complexType>
 </element>
</schema>

xml文件1:
<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="http://www.example.org/01"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.example.org/01">
 <id>1</id>
 <username>zhangsan</username>
 <born>1989-12-22</born>
</user>

xml文件2:
<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="http://www.example.org/01"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="01.xsd">
  <id>11</id>
  <username>lisi</username>
  <born>1988-11-11</born>
</user>

schema文件2:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/02"
 xmlns:tns="http://www.example.org/02" elementFormDefault="qualified">

 <element name="books">
  <complexType>
  <!-- maxOccurs表示最大出现次数 -->
   <sequence maxOccurs="unbounded">
    <element name="book">
     <complexType>
      <sequence minOccurs="1" maxOccurs="unbounded">
       <element name="title" type="string" />
       <element name="content" type="string" />
       <choice>
        <element name="author" type="string" />
        <element name="authors">
         <complexType>
          <all><!-- 每个元素只能出现一次 -->
           <element name="author" type="string"/>
          </all>
         </complexType>
        </element>
       </choice>
      </sequence>
      <attribute name="id" type="int" use="required"/>
     </complexType>
    </element>
   </sequence>
  </complexType>
 </element>

</schema>


xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<book:books xmlns:book="http://www.example.org/02"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="02.xsd">
 <book:book id="1">
  <book:title>Java in action</book:title>
  <book:content>Java is good</book:content>
  <book:author>Bruce</book:author>
 </book:book>
 <book:book id="2">
  <book:title>SOA in action</book:title>
  <book:content>soa is difficult</book:content>
  <book:authors>
   <book:author>Jike</book:author>
  </book:authors>
 </book:book>
</book:books>

schema文件3:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.org/04"
  xmlns:tns="http://www.example.org/04"
  elementFormDefault="qualified">
  
 <element name="person" type="tns:personType"/>
 
 <complexType name="personType">
  <sequence>
   <element name="name" type="string"/>
   <element name="age" type="tns:ageType"/>
   <element name="email" type="tns:emailType"/>
  </sequence>
  <attribute name="sex" type="tns:sexType"/>
 </complexType>
 
 <simpleType name="emailType">
  <restriction base="string">
   <pattern value="(\w+\.*)*\w+@\w+\.[A-Za-z]{2,6}"/>
   <minLength value="6"/>
   <maxLength value="255"/>
  </restriction>
 </simpleType>
 
 <simpleType name="ageType">
  <restriction base="int">
   <minInclusive value="1"/>
   <maxExclusive value="150"/>
  </restriction>
 </simpleType>
 
 <simpleType name="sexType">
  <restriction base="string">
   <enumeration value="男"/>
   <enumeration value="女"/>
  </restriction>
 </simpleType>
</schema>

xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<person xmlns="http://www.example.org/04"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.example.org/04" sex="男">
  <name>搜索</name>
  <age>149</age>
  <email>sadf@sdf.css</email>
</person>

schema文件4:




posted on 2013-08-13 09:58 杨军威 阅读(160) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜