`
ekumen
  • 浏览: 105339 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

xmlStudy3-xml schema -1

    博客分类:
  • xml
XML 
阅读更多
1.对xml schema的引用
<?xml version="1.0"?>
<note
xmlns="http://www.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn note.xsd">

<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting this weekend!</body>
</note>
2.xml schema定义
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3school.com.cn"
xmlns="http://www.w3school.com.cn"
elementFormDefault="qualified">

<xs:element name="note">
    <xs:complexType>
      <xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>

</xs:schema>
3.<schema> 元素是每一个 XML Schema 的根元素
<schema> 元素可包含的属性:
1.  xmlns:xs=http://www.w3.org/2001/XMLSchema  
显示 schema 中用到的元素和数据类型来自命名空间 "http://www.w3.org/2001/XMLSchema"。同时它还规定了来自命名空间 "http://www.w3.org/2001/XMLSchema" 的元素和数据类型应该使用前缀 xs:
2.  targetNamespace=http://www.w3school.com.cn
显示被此 schema 定义的元素 (note, to, from, heading, body) 来自命名空间: http://www.w3school.com.cn。
3.  xmlns=http://www.w3school.com.cn
指出默认的命名空间是 http://www.w3school.com.cn。
4.  elementFormDefault="qualified"
指出任何 XML 实例文档所使用的且在此 schema 中声明过的元素必须被命名空间限定。

4.某个元素拥有属性,它就会被当作某种复合类型。

如需属性为必选,用 "use" 属性:<xs:attribute name="lang" type="xs:string" use="required"/>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics