以文本方式查看主题

-  中文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=30295)


--  作者:gemingke
--  发布时间:4/10/2006 12:34:00 PM

--  心得分享,关于数据约束和扩展
先给一个xml文档的片断:
    <货物价格 单位="元">5670.00</货物价格>

该片断的schema如下:
<xs:element name="货物价格">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="货物价格Type">
     <xs:attribute name="单位" use="required" fixed="元"/>
    </xs:extension>
   </xs:simpleContent>
  </xs:complexType>
 </xs:element>
 <xs:simpleType name="货物价格Type">
  <xs:restriction base="xs:decimal">
   <xs:minInclusive value="0"/>
   <xs:totalDigits value="10"/>
   <xs:fractionDigits value="2"/>
  </xs:restriction>
 </xs:simpleType>

如上所示,complexType里可以使用complexContentsimpleContent来对某种数据类型进行约束或扩展。上面的例子就是用simpleContent对“货物价格Type”进行扩展的实例。

这里要注意,complexContent的扩展或约束对象必须是complexTypesimpleContent的扩展或约束对象必须是simpleType

还要注意一点,complexContentsimpleContent在进行约束或扩展时,都不可以使用刻面 (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDidits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern) ,刻面的使用必须是在simpleTyperestriction下面


--  作者:highthand
--  发布时间:4/10/2006 5:58:00 PM

--  
很好!不知道楼主是否再写详细一些??谢谢!!!
--  作者:gemingke
--  发布时间:4/10/2006 10:55:00 PM

--  
详细?
--  作者:feirate
--  发布时间:4/14/2006 9:27:00 AM

--  
可以讲讲约束和扩展的不同么?
--  作者:kongmrjsj
--  发布时间:4/14/2006 11:10:00 AM

--  
thanks
--  作者:gemingke
--  发布时间:4/14/2006 12:42:00 PM

--  
使用complexContent或simpleContent的扩展,可以在基础数据类型上扩展出新元素和新属性~~~~约束目前还没有用过~~

我在想,约束可能用于使用某种数据格式而又想更多的限定明确


--  作者:mkun
--  发布时间:11/7/2008 10:39:00 PM

--  
能不要<xs:simpleContent>吗?
--  作者:goukili
--  发布时间:12/1/2008 7:02:00 PM

--  
初学,能否详细说明下 complexContent 和 simpleContent 的区别?两者分别在什么情况下使用?谢谢。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
66.406ms