关于XSD(XML模式定义)的妄加猜测(新手勿看(以防误导),高手指正)

来源:互联网 发布:适合25岁用的精华 知乎 编辑:程序博客网 时间:2024/06/05 18:00
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="book"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
xmlns:tns="http://example/book.xsd"
xmlns=" http://example/book.xsd "
targetNamespace=" http://example/book.xsd "
 elementFormDefault="qualified"
    <xsd:element name="element1">
    <xsd:complexType>
      <xsd:sequence />
    </xsd:complexType>
 </xsd:element> ......
</xsd:schema>
注:
1、xsd并非限定的,可以换成任意字符串,如:
<?xml version="1.0" encoding="utf-8"?>
<ab:schema id="book"
 targetNamespace="http://tempuri.org/book.xsd"
 elementFormDefault="qualified"
 xmlns="http://tempuri.org/book.xsd"
 xmlns:mstns="http://tempuri.org/book.xsd"
  xmlns:ab="http://www.w3.org/2001/XMLSchema">
 <ab:element name="element1">
    <ab:complexType>
      <ab:sequence />
    </ab:complexType>
 </ab:element>
</ab:schema>
2、xmlns:根元素命名空间前缀="http://www.w3.org/2001/XMLSchema"指定了根元素的命名空间,此部分不能更改。而且此代码在xsd(xml模式)文档中是必须的部分。
3、xmlns:(根元素以下)子元素命名空间前缀="http://example/book.xsd"可用xmlns指定任意多个命名空间前缀供targetNamespace属性使用,如例子中的xmlns:tns="http://example/book.xsd",其中“xmlns:”后的蓝色部分(根元素下级子元素的命名空间前缀)可以是不同于根元素命名空间前缀(如例子中的xsd、ab)的任何字符(串)。
4、xmlns=" http://example/book.xsd "属性指定没有前缀的(根元素下级)子元素的默认命间空间。该属性值可以不从xmlns: (根元素以下)子元素命名空间前缀属性指定的命名空间中选定,而是可以自由设置。
5、targetNamespace属性指定有前缀的(根元素下级)子元素的命名空间,该属性值必须从xmlns:子元素命名空间前缀或xmlns属性指定的命名空间中选定。
 
原创粉丝点击