今晚碰上了這個問題。
解決辦法是:在xsd的聲明中加:elementFormDefault=“qualified”
怪自己沒有加上這句話的習慣...
網上有很多攻略:在出錯的代碼前後加<jsp-config></jsp-config>,或是改version的值;或是將“xmlns="http://java.sun.com/xml/ns/j2ee"”直接刪掉等等。
不知爲何,都無法解決我的問題。
我的代碼可謂是最基礎的。
代碼如下:
xml:
<?xml version="1.0" encoding="utf-8"?>
<bookstore xmlns="http://www.example.org/ppt"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/ppt ppt.xsd"
>
<book > </book>
</bookstore>
xsd:
<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/ppt"
xmlns:tns="http://www.example.org/ppt"
>
<element name="bookstore">
<complexType>
<element name=“book” >
</element>
</complexType>
</element>
</schema>
後來呢,找到了這篇文章:http://bytes.com/topic/xml/answers/909955-cvc-complex-type-2-4-invalid-content-found
慶幸地是還懂點英文,不過樓主所說的解決辦法並不適用於我。倒是回答問題的人所說的辦法能解決我的問題。