我需要使用Xerces到無效的XML實例對架構:孩子命名空間前綴元素被認爲是無效的Xerces的
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
schemaLocation);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.parse(new InputSource(xml));
這裏是我的XML實例:
<?xml version="1.0"?>
<eml:eml packageId="tao.12926.1" system="knb" xmlns:eml="eml://ecoinformatics.org/eml-2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="eml://ecoinformatics.org/eml-2.1.0 eml.xsd">
<dataset>
.......
</dataset>
</eml:eml>
這個XML被認爲是有效的。
但是,如果我加前綴 「EML」,以元素 「數據集」:
<?xml version="1.0"?>
<eml:eml packageId="tao.12926.1" system="knb" xmlns:eml="eml://ecoinformatics.org/eml-2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="eml://ecoinformatics.org/eml-2.1.0 eml.xsd">
<eml:dataset>
.......
</eml:dataset>
</eml:eml>
它給我一個錯誤: CVC-複雜type.2.4.a:無效的內容開始元素「EML :數據集」。內容必須匹配'(((「」:access:){0-1},((((「」:dataset)|(「」:citation))|(「」:software))|(「」:protocol ))),( 「」:additionalMetadata){0-UNBOUNDED})」。
我無法理解這一點。 「數據集」在我們的模式定義期間具有默認的命名空間。 「數據集」只是「eml:dataset」的縮寫版本。爲什麼xerces不喜歡?
您能否給我一些線索?
謝謝!
數據集元素位於空名稱空間中,是什麼讓你以其他方式去思考? – Alohci 2009-10-01 21:37:34