以文本方式查看主题

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


--  作者:f1029303
--  发布时间:9/7/2007 3:36:00 PM

--  關于名字空間的問題(請高手解答)
<!--xml schema file-->
<?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" type="xs:string"/>
         <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>

<!--xml file -->
<?xml version="1.0" encoding="gb2312"?>
<bookshop xmlns="http://www.jeff.com/xmlschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jeff.com/xmlschema
E:\TRAINI~1\XML\example\bigExample.xsd" shopname="xin hua bookshop">
 <books>
  <book memo="one edition">
   <name>xml study</name>
   <ISBN>7-302-06096-7</ISBN>
   <price>46.00</price>
   <public>tinhua university public</public>
   <phone>0010-62802520</phone>
  </book>
  <otherInfor recordPeople="jeff" recordDate="2007-09-10">
   <buyDate>2007-09-10</buyDate>
   <isDestroy>true</isDestroy>
   <number>100</number>
  </otherInfor>
 </books>
</bookshop>


以上的程序沒有問題。
引用了源名字空間﹐但是我改動源名稱如:
xmlns:jeffreg="http://example.org/test"
<xs:import namespace="http://example.org/test" schemaLocation="E:\Training Doc\XML\example\example9.xsd"/>
這樣就提示錯誤﹐難道prod是默認的?
包括http://example.org/prod也不能改動﹐當然我改的符合URL規范。
請高手解答﹐


[此贴子已经被作者于2007-9-10 16:22:35编辑过]

--  作者:mlmzw
--  发布时间:9/19/2007 10:13:00 AM

--  
可能是你的E:\Training Doc\XML\example\example9.xsd对http://example.org/prod进行了定义
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms