Hello everybody,
i've a courios problem with schema-validation. There is a problem with
the namespace, which contains 'strange' UTF-8-characters (codes: 516C /
53F8). Is it posible that xerces do something wrong with the
schema-targetnamespace??
Thanks for helping :-)
igor :-)
Here some code-snipplets...
XML-File:
<?xml version="1.0" encoding="UTF-8"?>
<ns:root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="ns-公司-test src/testData/schema.xsd"
xmlns:ns="ns-公司-test">
<child>test</child>
</ns:root>
SCHEMA-File:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:local="ns-公司-test"
targetNamespace="ns-公司-test">
<xsd:element name="root" type="local:rootType"/>
<xsd:complexType name="rootType">
<xsd:sequence>
<xsd:element type="xsd:string" name="child"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
RESULT:
- org.jdom.input.JDOMParseException: Error on line 4 of document
file:///D:/develop/eclipse-workspace-head/validationtestProject/src/testData/schema.xsd:
TargetNamespace.1: Expecting namespace 'ns-??-test', but the target
namespace of the schema document is 'ns-%E5%85%AC%E5%8F%B8-test'.
JAVA-CODE for Validation:
/** Schema location feature id
"http://apache.org/xml/properties/schema/external-SchemaLocation" */
public static final String EXTERNAL_SCHEMA_LOCATION_ID =
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
/** Namespaces feature id (http://xml.org/sax/features/namespaces). */
public static final String NAMESPACES_FEATURE_ID =
Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
/** Validation feature id (http://xml.org/sax/features/validation). */
public static final String VALIDATION_FEATURE_ID =
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
/** Schema validation feature id
(http://apache.org/xml/features/validation/schema). */
public static final String SCHEMA_VALIDATION_FEATURE_ID =
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
/** Schema full checking feature id
(http://apache.org/xml/features/validation/schema-full-checking). */
public static final String SCHEMA_FULL_CHECKING_FEATURE_ID =
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
public static final String PARSER_CONFIGURATION =
"org.apache.xerces.xni.parser.XMLParserConfiguration";
public static final String XERCES_FACTORY =
"org.apache.xerces.jaxp.SAXParserFactoryImpl";
public static final String SAXPARSER_FACTORY =
"javax.xml.parsers.SAXParserFactory";
public static final String GRAMMAR_CACHING_PARSER =
"org.apache.xerces.parsers.XMLGrammarCachingConfiguration";
public void testSimple() {
try {
System.setProperty (PARSER_CONFIGURATION, GRAMMAR_CACHING_PARSER);
System.setProperty (SAXPARSER_FACTORY, XERCES_FACTORY);
try {
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setFeature (SCHEMA_VALIDATION_FEATURE_ID, true);
saxBuilder.setFeature (SCHEMA_FULL_CHECKING_FEATURE_ID, true);
Document outDoc = saxBuilder.build(
this.getClass().getResourceAsStream("/testdata/data.xml"));
XMLOutputter xop = new XMLOutputter(Format.getPrettyFormat());
LOG.info(xop.outputString(outDoc));
} catch (JDOMException ex) {
LOG.error (ex, ex);
} catch (IOException e) {
LOG.error (e, e);
}
} catch (Throwable t) {
fail(t.getMessage());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]