schema-location なしでインポートを含む 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では、systemId = nullで起動された ResourceResolver 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: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'.. Saw 'The "xml:" Namespace '。
どんな助けでも大歓迎です。