以文本方式查看主题

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


--  作者:Theface
--  发布时间:12/28/2006 9:21:00 PM

--  [求助]请教一个名称空间(我想应该是吧)的问题.一直在郁闷 ....
我定义的XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.mesoft.com.cn/XMLSchema" targetNamespace="http://www.mesoft.com.cn/XMLSchema">
 <xs:element name="System-Config">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Analyzer-Config">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="Analyzer" maxOccurs="unbounded">
        <xs:complexType>
         <xs:attribute name="name" type="xs:NMTOKEN" use="required"/>
         <xs:attribute name="class" type="xs:NMTOKEN" use="required"/>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
   <xs:attribute name="name" type="xs:string"/>
  </xs:complexType>
 </xs:element>
</xs:schema>

最终应用此XSD的XML文件:
<p:System-Config version="" xsi:schemaLocation="http://www.mesoft.com.cn/XMLSchema Index-Config.xsd" xmlns:p="http://www.mesoft.com.cn/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <Analyzer-Config>
  <Analyzer name="daf" class="daf"/>
 </Analyzer-Config>
</p:System-Config>
我这里不知道为什么必须要加p,或者说xmlns后面必须要有个名称空间定义,这样这个XML才能被验证.否则就不可以,比如:
<System-Config version="" xsi:schemaLocation="http://www.mesoft.com.cn/XMLSchema Index-Config.xsd" xmlns="http://www.mesoft.com.cn/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <Analyzer-Config>
  <Analyzer name="daf" class="daf"/>
 </Analyzer-Config>
</System-Config>
这样就不行.
但是我如果用第一种方式(在xmlns后面加冒号并带个名称)的话.JDK1.5以前的版本是不能读的.它会说找不到根.而第二种方式会使这个XSD约束不起作用....

一直在因为这个问题郁闷..请各位帮忙一下.


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