【发布时间】:2012-01-13 00:21:09
【问题描述】:
我正在尝试使用以下代码从给定 XSD 文件中验证我的 XML 文件,
Source xmlFile = new StreamSource(fXmlFile);
SchemaFactory schemaFactory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(new File("presentation.xsd"));
Validator validator = schema.newValidator();
try {
validator.validate(xmlFile);
System.out.println(xmlFile.getSystemId() + " is valid");
} catch (SAXException e) {
System.out.println(xmlFile.getSystemId() + " is NOT valid");
System.out.println("Reason: " + e.getLocalizedMessage());
}
我把我的 XSD 文件上传到这里给你看:http://orhancanceylan.com/stack/presentation.xsd
但是当我运行我的代码时,我得到了这个错误:
org.xml.sax.SAXParseException: s4s-att-not-allowed: Attribute 'maxOccurs' cannot appear in element 'element'.
什么问题,我应该怎么解决?
【问题讨论】:
标签: java xml validation xsd