以文本方式查看主题

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


--  作者:lish
--  发布时间:9/13/2007 3:03:00 PM

--  命名空间的理解
<schema targetNamespace="http://www.example.com/IPO"
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:ipo="http://www.example.com/IPO">

在这个Tag中,有三个属性
属性targetNamespace规定依据本Schema文档定义的xml中元素的命名空间
属性xmlns规定了默认的命名空间,即Schema中的元素的命名空间
属性xmlns:ipo规定了ipo这个命名空间

我理解的对么?但感觉分不太清targetNamespace和xmlns

请求支援!谢谢


--  作者:f1029303
--  发布时间:9/14/2007 11:37:00 AM

--  
chapter 1:
<schema targetNamespace="http://www.example.com/IPO"
        xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:ipo="http://www.example.com/IPO">

是這樣理解的
targetNamespace="http://www.example.com/IPO"
xmlns:ipo="http://www.example.com/IPO"
這個是   目标名字空间(target namespace)
一個xmlschema文檔只能有一個 目标名字空间
xmlns 是必須的帶上的﹐
ipo是命名前綴﹐作用是下面XML文檔中﹐
如果是目标名字空间的類型﹐前綴就可以改為 ipo:xxxx

chapter 2:
xmlns="http://www.w3.org/2001/XMLSchema"
這個是 标准名字空间(standard namespace)
它是定义Schema语法的标准﹐由w3c來定義的﹐
這個不多說。


chapter 3:
還有如下的
<schema targetNamespace='http://www.SampleStore.com/Account'
    xmlns='http://www.w3.org/1999/xmlSchema'
    xmlns:ACC= 'http://www.SampleStore.com/Account'
    xmlns:PART= 'http://www.PartnerStore.com/PartsCatalog'>

  <import namespace='http://www.PartnerStore.com/PartsCatalog'
    schemaLocation='http://www.ProductStandards.org/repository/alpha.xsd'/>


xmlns:PART= 'http://www.PartnerStore.com/PartsCatalog'

<import namespace='http://www.PartnerStore.com/PartsCatalog'
    schemaLocation='http://www.ProductStandards.org/repository/alpha.xsd'/>

這個是 源名字空间(source namespaces)
一個xmlschema文檔可以有多個 源名字空间(目前我只能引用一個,引用兩個以上的﹐沒有辦法加前綴﹐一直都沒有找到資料)

chapter4:
以下是代碼你可以看看有沒有幫助
<?xml version="1.0" encoding="gb2312"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jeff="http://www.jeff.com/xmlschema" xmlns:jeffreg="http://example.org/prod" targetNamespace="http://www.jeff.com/xmlschema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:import namespace="http://example.org/prod" schemaLocation="E:\Training Doc\XML\example\example9.xsd"/>
 <xs:element name="bookshop">
  <xs:annotation>
   <xs:documentation>this is example</xs:documentation>
  </xs:annotation>
  <xs:complexType>
   <xs:sequence>
    <xs:element name="books" maxOccurs="unbounded">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="book">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="name" type="xs:string"/>
          <xs:element name="ISBN">
           <xs:simpleType>
            <xs:restriction base="xs:string">
             <xs:pattern value="\d{1}-\d{3}-\d{5}-\d{1}"/>
            </xs:restriction>
           </xs:simpleType>
          </xs:element>
          <xs:element name="price" type="xs:double"/>
          <xs:element name="public" type="xs:string"/>
          <xs:choice>
           <xs:element name="author" type="xs:string"/>
           <xs:element name="phone" type="jeff:stringSpec"/>
          </xs:choice>
         </xs:sequence>
         <xs:attribute name="memo" type="xs:string"/>
        </xs:complexType>
       </xs:element>
       <xs:element name="otherInfor">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="buyDate" type="jeff:dateFormat"/>
          <xs:element name="isDestroy" type="xs:boolean"/>
          <xs:element name="number" type="jeffreg:SizeType"/>
         </xs:sequence>
         <xs:attribute name="recordPeople">
          <xs:simpleType>
           <xs:restriction base="xs:string">
            <xs:enumeration value="jeff"/>
            <xs:enumeration value="jeffreg"/>
            <xs:enumeration value="admin"/>
           </xs:restriction>
          </xs:simpleType>
         </xs:attribute>
         <xs:attribute name="recordDate" type="jeff:dateFormat"/>
         <!--attribute recordpeople-->
        </xs:complexType>
       </xs:element>
      </xs:sequence>
      <xs:attribute name="index" type="jeff:stringIndex"/>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
   <xs:attribute name="shopname" type="xs:string"/>
  </xs:complexType>
 </xs:element>
 <!--attribute bookAttribute
 <xs:attributeGroup name="bookAttribute">
 <xs:attribute name="memo" type="xs:string"/> 
 </xs:attributeGroup>
 -->
 <!--simple type  stringSpec-->
 <xs:simpleType name="stringSpec">
  <xs:restriction base="xs:string">
   <xs:pattern value="\d{4}-\d{8}"/>
  </xs:restriction>
 </xs:simpleType>
 <!--simple type  dateFormat-->
 <xs:simpleType name="dateFormat">
  <xs:restriction base="xs:date">
   <xs:pattern value="\d{4}-\d{2}-\d{2}"/>
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="stringIndex">
  <xs:restriction base="xs:string">
   <xs:pattern value="\d{4}"/>
  </xs:restriction>
 </xs:simpleType>
</xs:schema>


--  作者:lish
--  发布时间:9/18/2007 9:02:00 AM

--  
f1029303 ,非常感谢!

xmlns="http://www.w3.org/2001/XMLSchema"
如果Schema中的语法元素前不加前缀,用上面的namespace声明方式
如果Schema中的语法元素前加xs,用下面的namespace声明方式
xmlns:xs="http://www.w3.org/2001/XMLSchema"

对吧

很笨,呵呵

现在遇到这样的问题:自动合并两个xml文档
我的思路:首先找到两个xml Schema,然后合并两个Schema,即建立一个新的Schema,把原来的old Schema的根节点作为new Schema的第一层子节点,再根据Schema合并xml文档内容

可是现在的问题是,合并Schema时,我知道Schema好像用import可以直接引入其它Schema,但是对于具体的使用还不太清楚,正在学习W3C上的官方文档,不知道这种方式是否正确。

不知道有没有人遇到过这种问题,都是怎么解决的,请提示,谢谢。


--  作者:九剑华
--  发布时间:9/28/2007 4:06:00 PM

--  
以下是引用lish在2007-9-18 9:02:00的发言:
f1029303 ,非常感谢!

xmlns="http://www.w3.org/2001/XMLSchema"
如果Schema中的语法元素前不加前缀,用上面的namespace声明方式
如果Schema中的语法元素前加xs,用下面的namespace声明方式
xmlns:xs="http://www.w3.org/2001/XMLSchema"

对吧

很笨,呵呵

现在遇到这样的问题:自动合并两个xml文档
我的思路:首先找到两个xml Schema,然后合并两个Schema,即建立一个新的Schema,把原来的old Schema的根节点作为new Schema的第一层子节点,再根据Schema合并xml文档内容

可是现在的问题是,合并Schema时,我知道Schema好像用import可以直接引入其它Schema,但是对于具体的使用还不太清楚,正在学习W3C上的官方文档,不知道这种方式是否正确。

不知道有没有人遇到过这种问题,都是怎么解决的,请提示,谢谢。


如果加前缀的话是不是只能加xs?
还有目标名字空间,标准名字空间,源名字空间这3着有什么区别?


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
94.727ms