个人备忘--schema

xs:complexType使用方法比较:

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://mynamespace/schema">
<xs:element name="书本">
<xs:complexType>
        <xs:attribute name="名称" type="xs:string"/>
        <xs:attribute name="作者" type="xs:string"/>
</xs:complexType>
</xs:element>

</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>
<书本 xmlns="http://mynamespace/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mynamespace/schema file:///C:/Documents%20and%20Settings/Administrator/%e6%a1%8c%e9%9d%a2/Untitled1.xsd" 名称="书籍" 作者="hehe"/>


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="element" type="myElementType"/>
<xs:complexType name="myElementType">
    <xs:attributeGroup ref="myAttributeGroup"/>
</xs:complexType>
<xs:attributeGroup name="myAttributeGroup">
    <xs:attribute name="someattribute1" type="xs:integer" use="required"/>
    <xs:attribute name="someattribute2" type="xs:string"/>
</xs:attributeGroup>
</xs:schema>


<?xml version="1.0" encoding="UTF-8"?>
<element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/Documents%20and%20Settings/Administrator/%e6%a1%8c%e9%9d%a2/Untitled1.xsd" someattribute1="4"/>


simpleContent元素:
应用于complexType,对它的内容进行约束和扩展。

l作用:定义一个简单类型,它决定了元素和属性值的约束和相关信息
l属性: name
l内容:应用已经存在的简单类型,三种方式:
l restriction→限定一个范围
l list→从列表中选择
l union→包含一个值的结合
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="allframesize">
  <xs:simpleType>
    <xs:union>
      <xs:simpleType>
        <xs:restriction base="roadbikesize"/>
      </xs:simpleType>
      <xs:simpleType>
        <xs:restriction base="mountainbikesize"/>
      </xs:simpleType>
    </xs:union>
  </xs:simpleType>
</xs:attribute>

complexType与simpleType区别(重要)
l simpleType类型的元素中不能包含元素或者属性。
l当需要声明一个元素的子元素和/或属性时,用 complexType
l当需要基于内置的基本数据类型定义一个新的数据类型时,用 simpleType

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值