2014-07-25 80 views
1

編輯:做了些許修改。我想我接近了一點,但仍然無法工作。所有當前信息如下:導入XML Schema

我成功創建了一個XSD文件來驗證XML文件,但是我想將XSD文件拆分爲另一個文件。我相信我需要在XML文件中使用一個import元素來做到這一點,但我正在努力讓它工作。以下是我現在所擁有的在XML文件的頂部:

<?xml version="1.0" encoding="UTF-8"?> 
<presentations xmlns="http://www.brett.com/presentations" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.brett.com/presentations presentations_vb.xsd" 
> 

這裏是主要的XSD文件的開頭部分:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns="http://www.brett.com/presentations" 
targetNamespace="http://www.brett.com/presentations" 
elementFormDefault="qualified"> 

<!-- Here is the line in question --> 
<xs:import namespace="http://www.brett.com/presentations/topic" schemaLocation="http://www.brett.com/presentations topic_vb.xsd" /> 

這裏是我想新的XSD文件進口:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns="http://www.brett.com/presentations/topic" 
targetNamespace="http://www.brett.com/presentations/topic" 
elementFormDefault="qualified"> 

<!-- Topic Element --> 
    <xs:complexType name="topicType"> 
     <xs:simpleContent> 
     <xs:extension base="xs:string"> 
      <xs:attribute name="genre" use="required"> 
      <xs:simpleType> 
       <xs:restriction base="xs:string"> 
       <xs:enumeration value="ART" /> 
       <xs:enumeration value="Music" /> 
       <xs:enumeration value="Science" /> 
       <xs:enumeration value="Technology" /> 
       </xs:restriction> 
      </xs:simpleType> 
      </xs:attribute> 
     </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 

    <xs:element name="topic" type="topicType" /> 
</xs:schema> 

在將XSD分解爲兩個文件之前,所有內容都經過格式良好和驗證。我很確定我錯誤地導入了它,但我無法弄清楚正確的方法。嘗試驗證XML文件(XSD文件仍然生效)時出現以下錯誤:「FatalError在第0行,第0列:URL中不受支持的協議」

任何人都可以幫忙嗎?

+0

你真的有名字中的空間?空間應該用'%20'編碼,不是嗎?參見[RFC 3986](https://tools.ietf.org/html/rfc3986#section-2.1) – koppor

回答

1

在這裏麻煩的是,xs:import/@schemaLocation是不一樣的xs:schema/@xsi:schemaLocation

因此,請刪除xs:import/@schemaLocation值的名稱空間部分,並將URI留給XSD。

具體變化:

<xs:import namespace="http://www.brett.com/presentations/topic" 
      schemaLocation="http://www.brett.com/presentations topic_vb.xsd" /> 

到:

<xs:import namespace="http://www.brett.com/presentations/topic" 
      schemaLocation="topic_vb.xsd" /> 

(或任何用於topic_vb.xsd您的實際URI是當然的,)