我需要使用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