如何针对包含没有模式位置的导入的 XSD 模式验证 XML?
XSD 的片段:
<xs:schema xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types
xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.microsoft.com/exchange/services/2006/types"
elementFormDefault="qualified" version="Exchange2010_SP2" id="types">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
...
已经阅读并尝试过:
无法从架构中删除此导入,因为它包含 xml:lang 属性的引用。
在变体 1 ResourceResolver 中,使用 systemId = null触发的 resolveResource 方法
public class ResourceResolver implements LSResourceResolver {
public LSInput resolveResource(String type, String namespaceURI,
String publicId, String systemId, String baseURI) {
//Some implementation
return new Input(publicId, systemId, resourceAsStream);
在变体 2中尝试这样:
SchemaFactory sFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
//sFactory.setResourceResolver(new ResourceResolver());
Schema schema = sFactory.newSchema(new Source[] {
new StreamSource("http://www.w3.org/XML/1998/namespace"),
new StreamSource(MailGateMQBinding.class.getResourceAsStream("/types.xsd")),
});
validator = messageSchema.newValidator();
source = new DOMSource(inDocBody);
validator.validate(source);
但是有一个例外:没有new StreamSource("http://www.w3.org/XML/1998/namespace")
org.xml.sax.SAXParseException:src-resolve:无法将名称'xml:lang'解析为(n)'属性声明'。
并使用此new StreamSource("http://www.w3.org/XML/1998/namespace")
org.xml.sax.SAXParseException: s4s-elt-character: 除“xs:appinfo”和“xs:documentation”之外的架构元素中不允许使用非空白字符。看到“xml:”命名空间'。
任何帮助将不胜感激。