Validierung von XML gegen XSD, das xsd: import without location enthält
Wie validiere ich XML anhand des XSD-Schemas, das den Import ohne Schema-Speicherort enthält?
Fragment von 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"/>
...
Bereits gelesen und ausprobiert:
Dieses undDas auch... erfolglos.
Dieser Import kann nicht aus dem Schema entfernt werden, da er den Verweis auf das Attribut xml: lang enthält.
ImVariante 1 ResourceResolver resolveResource-Methode, die mit systemId = ausgelöst wurdeNull
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);
ImVariante 2 versucht so:
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);
Aber eine Ausnahme: ohnenew StreamSource("http://www.w3.org/XML/1998/namespace")
org.xml.sax.SAXParseException: src-resolve: Der Name 'xml: lang' kann nicht in eine (n) 'Attributdeklaration' aufgelöst werden.
und damitnew StreamSource("http://www.w3.org/XML/1998/namespace")
org.xml.sax.SAXParseException: s4s-elt-character: Nicht-Whitespace-Zeichen sind in anderen Schemaelementen als 'xs: appinfo' und 'xs: documentation' nicht zulässig. Saw 'Der Namespace "xml:".
Jede Hilfe wäre sehr dankbar.