以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  我问题一大堆  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=55276)


--  作者:xml-linguist
--  发布时间:11/13/2007 11:29:00 AM

--  我问题一大堆
我相信认真的浏览一下schema部分的帖子,我的问题应该可以解决。但是现在时间比较匆忙,先提出急需解决的问题。

先看book.xml文件:

<?xml version="1.0" encoding="GB2312"?>
<booklist xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xsi:noNamesapceSchemeLocation="book.xsd">
<book sales="Y">
  <code>F3333</code>
  <title>书名一</title>
  <authorlst>
    <author>张三</author>
  </athorlst>
  <price>58</price>
</book>
<book sales="N">
  <code>F444ode>
  <title>书名二</title>
  <authorlst>
    <author>李四</author>
  </athorlst>
  <price>55/price>
</book>
</booklist>

再看该xml文件的两个xsd文件:

book.xsd (01)
<?xml version="1.0" encoding="GB2312"?>
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:element name="booklist">
  <xsd:complextType content="elementOnly">
   <xsd:element name="book" type="bookType" minOccurs="1" maxOccurs="unbounded"/>
  </xsd:complexType>
</xsd:element>
<xsd:complexType name="bookBase">
  <xsd:sequence>
   <xsd:element name="code" type="xsd:string"/>
   <xsd:element name="title" type="xsd:string"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType" base="bookBase" derivedBy=“extension”>
  <xsd:sequence>
   <xsd:element name="authorlist" type="authorlistType"/>
   <xsd:element name="price" type="xsd:decimal"/>
  </xsd:sequence>
  <xsd:attribute name="sale" use="required">
   <xsd:simpleType base="xsd:NMTOKEN">
    <xsd:enumeration value="Y"/>
    <xsd:enumeration value="N"/>
   </xsd:simpleType>
  </xsd:attribute>
</xsd:complexType>
<xsd:complexType name="authorlistType" content="elementOnly">
  <xsd:element name="author" type="xsd:string minOccurs="0" maxOccurs="1"/>
</xsd:complexType>
</xsd:schema>


book.xsd (02)
<?xml version="1.0" encoding="GB2312"?>
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:element name="booklist">
  <xsd:complextType content="elementOnly">
   <xsd:element name="book" type="bookType" minOccurs="1" maxOccurs="unbounded"/>
  </xsd:complexType>
</xsd:element>
<xsd:complexType name="authorBase">
  <xsd:element name="author" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/>
</xsd:complexType>
<xsd:complexType name="authorType" base="authorBase" derivedBy="restriction“>
  <xsd:element name="author" type="xsd:string minOccurs="0" maxOccurs="1"/>
</xsd:complexType>
<xsd:complexType name="bookType" content="elementOnly">
  <xsd:sequence>
   <xsd:element name="code" type="xsd:string"/>
   <xsd:element name="title" type="xsd:string"/>
   <xsd:element name="authorist" type="authorType"/>
   <xsd:element name="price" type="xsd:decimal"/>
  </xsd:sequence>
</xsd:complexType>
</xsd:schema>
==============================
[face=楷体_GB2312][color=#0000FF]先在这里谢谢大家了![/color][/face]


--  作者:xml-linguist
--  发布时间:11/13/2007 11:33:00 AM

--  
第一个问题:derivedBy这个属性是用来做什么的?因此,它的两个属性值"extension"和"restriction"也不清楚。
--  作者:VictorWoo
--  发布时间:11/27/2007 5:14:00 PM

--  
同关注这个问题,今天刚刚碰到。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
64.453ms