Announcement

Collapse
No announcement yet.

Xerces Validierung: Keine Namespaces

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Xerces Validierung: Keine Namespaces

    Hi,

    ich versuche grade aus Ermangelung von anderen Möglichkeiten (also bitte keine Antworten wie: nimm doch JAXP) mit Xerces eine XML Datei gegen ein Schema zu validieren.

    Dabei habe ich das Problem, dass ich bei der Validierung lafuend auf die Meldung:

    TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'XYZ'.

    ... stoße. Anscheinend stimmen also die Namespaces im Zieldokument nicht 100%ig mit dem Schema überein. Das Problem ist aber: laut Kundendefinition ist das Dokument trotzdem valide .

    Ich würde jetzt gern die Namespace Validierung ausschalten, aber das gelingt mir irgendwie nicht wirklich. Hat jemand eine Idee, was ich falsch mache?

    Hier mein Code:
    /** Namespaces feature id (http://xml.org/sax/features/namespaces). */
    protected static final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces";

    /** Namespace prefixes feature id (http://xml.org/sax/features/namespace-prefixes). */
    protected static final String NAMESPACE_PREFIXES_FEATURE_ID = "http://xml.org/sax/features/namespace-prefixes";

    /** Validation feature id (http://xml.org/sax/features/validation). */
    protected static final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation";

    /** Schema validation feature id (http://apache.org/xml/features/validation/schema). */
    protected static final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema";

    /** Schema full checking feature id (http://apache.org/xml/features/valid...full-checking). */
    protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking";

    /** Dynamic validation feature id (http://apache.org/xml/features/validation/dynamic). */
    protected static final String DYNAMIC_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/dynamic";

    protected static final String SCHEMA_NONS_LOCATION_ID = "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";

    ...

    SAXParserFactory saxfactory = SAXParserFactory.newInstance();

    saxfactory.setValidating(true);
    saxfactory.setNamespaceAware(false);

    SAXParser parser = saxfactory.newSAXParser();

    XMLReader reader = parser.getXMLReader();

    reader.setFeature(NAMESPACES_FEATURE_ID, false);
    reader.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, false);
    reader.setFeature(VALIDATION_FEATURE_ID, true);
    reader.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
    reader.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, false);
    reader.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, false);

    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);

    reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdFile.toURL().toString());

    reader.parse(inp);
Working...
X