我有一个 XSD 文件:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="someNameSpace"
xmlns="someNameSpace"
elementFormDefault="qualified">
...
</xs:schema>
在 Java 代码中:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringElementContentWhitespace(true);
dbf.setIgnoringComments(true);
dbf.setFeature("http://apache.org/xml/features/validation/schema", true);
dbf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
dbf.setAttribute("http://apache.org/xml/properties/schema/external-schemaLocation", "someNameSpace file:///home/.../schema.xsd");
DocumentBuilder builder = dbf.newDocumentBuilder();
builder.setErrorHandler(new SomeHandlerImpl());
Document doc = builder.parse(input);
输入是一个文件,开头为:
<?xml version="1.0" encoding="UTF-8"?>
<projekt xmlns="someNameSpace">
如果我删除命名空间并改用http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
属性http://apache.org/xml/properties/schema/external-schemaLocation
,它就可以工作。但是对于命名空间,我完全不知道该怎么办。