FORTUNE

THE WAY TO THE MASTER...
posts - 49, comments - 18, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

xsd的两个例子

Posted on 2006-03-26 20:47 fortune 阅读(1012) 评论(0)  编辑  收藏 所属分类: java技术

noNamspace schema的:

<?xml version="1.0" encoding="gb2312"?>
<!-- PRODUCTDATA是根元素-->
<PRODUCTDATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="F:\XML\2\BookSaleS.XSD">
 <PRODUCT>
  <BookTitle>JAVA核心技术</BookTitle>
  <BookISBN>I001</BookISBN>
  <FAuthor>John Sun</FAuthor>
  <LAuthor>May Rose</LAuthor>
  <BookPrice>45</BookPrice>
 </PRODUCT>
</PRODUCTDATA>


下面是XSD文件(BookSales.xsd)

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="PRODUCTDATA" type="PRODATA"/>
 <xsd:complexType name="PRODATA">
  <xsd:sequence>
   <xsd:element name="PRODUCT" type="PROC"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="PROC">
  <xsd:sequence>
   <xsd:element name="BookTitle" type="xsd:string"/>
   <xsd:element name="BookISBN" type="xsd:string"/>
   <xsd:element name="FAuthor" type="xsd:string"/>
   <xsd:element name="LAuthor" type="xsd:string"/>
   <xsd:element name="BookPrice" type="xsd:positiveInteger"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:schema>

有命名空间的:
<?xml version="1.0" encoding="GBK"?>
<qqq:MOVIEINFO xmlns:qqq="n" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="n
F:\4\4.2\Movie.xsd">
 <MOVIES>
  <MOVIE ID="Q0024">
   <MOVIETYPE>
    <ROMANTIC>浪漫</ROMANTIC>
   </MOVIETYPE>
   <MOVIEDATE>2003-12-12</MOVIEDATE>
   <MOVIENAME>人鬼情未了</MOVIENAME>
   <PLAYACTORS>
    <PLAYACTOR>Tom1</PLAYACTOR>
    <PLAYACTOR>Tom2</PLAYACTOR>
    <PLAYACTOR>Tom3</PLAYACTOR>
    <PLAYACTOR>Tom3</PLAYACTOR>
   </PLAYACTORS>
   <DIRECT>Tom Jone</DIRECT>
   <HORTATION>100万</HORTATION>
  </MOVIE>
  <MOVIE ID="Q0404">
   <MOVIETYPE>
    <COMEDY>浪漫</COMEDY>
   </MOVIETYPE>
   <MOVIEDATE>2003-12-12</MOVIEDATE>
   <MOVIENAME>人鬼情未了</MOVIENAME>
   <PLAYACTORS>
    <PLAYACTOR>Tom1</PLAYACTOR>
    <PLAYACTOR>Tom2</PLAYACTOR>
    <PLAYACTOR>Tom3</PLAYACTOR>
    <PLAYACTOR>Tom3</PLAYACTOR>
   </PLAYACTORS>
   <DIRECT>Tom Jone</DIRECT>
   <HORTATION>100万</HORTATION>
  </MOVIE>
 </MOVIES>
</qqq:MOVIEINFO>


XSD文件:(Movie.xsd)

<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema" targetNamespace="n" xmlns:a="n">
 <s:include schemaLocation="Id.xsd"/>
 <s:element name="MOVIEINFO" type="a:suType"/>
 <s:complexType name="suType">
  <s:sequence>
   <s:element name="MOVIES" type="a:ppType"/>
  </s:sequence>
 </s:complexType>
 <s:complexType name="ppType">
  <s:sequence>
   <s:element name="MOVIE" type="a:uuType" maxOccurs="5"/>
  </s:sequence>
 </s:complexType>
 <s:complexType name="uuType">
  <s:sequence>
   <s:element name="MOVIETYPE" type="a:prd"/>
   <s:element name="MOVIEDATE" type="s:string"/>
   <s:element name="MOVIENAME" type="s:string"/>
   <s:element name="PLAYACTORS" type="a:pod"/>
   <s:element name="DIRECT" type="s:string"/>
   <s:element name="HORTATION" type="s:string"/>
  </s:sequence>
  <s:attribute name="ID" type="a:ppp"/>
 </s:complexType>
 <s:complexType name="prd">
  <s:choice>
   <s:element name="DROLLNESS" type="s:string"/>
   <s:element name="ROMANTIC" type="s:string"/>
   <s:element name="COMEDY" type="s:string"/>
   <s:element name="DRAMA" type="s:string"/>
   <s:element name="ACTION" type="s:string"/>
  </s:choice>
 </s:complexType>
 <s:complexType name="pod">
  <s:sequence>
   <s:element name="PLAYACTOR" type="s:string" maxOccurs="5"/>
  </s:sequence>
 </s:complexType>
</s:schema>

XSD文件:(ID.xsd)

<xsd:schema targetNamespace="n" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:simpleType name="ppp">
  <xsd:restriction base="xsd:string">
   <xsd:pattern value="[Q]{1}\d{4}"/>
  </xsd:restriction>
 </xsd:simpleType>
</xsd:schema>


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


网站导航: