2013-05-21 13 views
16

我得到以下錯誤錯誤:「schemaLocation值***必須有偶數個URI」。在春季調度命名空間

<Ignored XML validation warning> org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 55; 
SchemaLocation: schemaLocation value = 'http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
http://www.springframework.org/schema/tx' must have even number of URI's. 

和我的分發程序Servlet爲具有下列命名空間

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

,我更換了所有上述通過以下

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

和我錯誤消失了。
它是如何發生的?

回答

56

schemaLocation屬性引用名稱空間的XML Schema文檔。

基本上當你鍵入:

xmlns:expns="http://www.example.com" 
xsi:schemaLocation="http://www.example.com 
        http://www.example.com/schema/example.xsd" 

你是在說:我將使用前綴expns的命名空間的http://www.example.com同樣的元素,所以你可以驗證。這些元素,得到http://www.example.comXSD架構文件中http://www.example.com/schema/example.xsd

因此,換句話說,格式是:

xsi:schemaLocation="namespace-a where_to_get_the_xsd_for_namespace-a 
        namespace-b where_to_get_the_xsd_for_namespace-b 
        namespace-c where_to_get_the_xsd_for_namespace-c" 

等。

這就是爲什麼它必須是我的甚至號碼。


更多的信息和例子可以發現here

+0

那麼你如何解決這個問題?你是否剛剛移除了未正確格式化的'xsi:schemaLocation',因爲它實際上並沒有做任何事情?你知道命名空間應該是什麼嗎?如果是這樣,怎麼樣? –

+0

@StephenOstermiller您可以修復(添加對應項)xsi:schemaLocation中使其不均勻的條目,或者,如果您不知道conterpart的正確值,請刪除條目(因此不需要刪除整個'xsi:schemaLocation',儘管這也會起作用,我想)。 – acdcjunior

相關問題