]
Arron Ferguson commented on JBSEAM-2938:
----------------------------------------
Not sure if:
saxReader.setEntityResolver(new DTDEntityResolver());
saxReader.setValidation(true);
;
With newer JVMs. Sun went and changed the whole XSD validation process and now requires
you to use a SchemaFactory. Take a look at the code I put up in the closed/duplicate bug:
org.jboss.seam.util.XML doesn't validate
----------------------------------------
Key: JBSEAM-2938
URL:
https://jira.jboss.org/jira/browse/JBSEAM-2938
Project: Seam
Issue Type: Bug
Components: Core
Reporter: Christian Bauer
Assignee: Norman Richards
Priority: Minor
The getRootElement() method is probably supposed to validate the XML file. However, it
only sets a DTD EntityResolver:
SAXReader saxReader = new SAXReader();
saxReader.setEntityResolver(new DTDEntityResolver());
saxReader.setMergeAdjacentText(true);
return saxReader.read(stream).getRootElement();
This might trigger some magic flag that says "validate against this DTD", but
the dom4j documentation says otherwise:
http://www.dom4j.org/faq.html#how-validate
I've implemented my own routine which validates against my schema properly:
try {
SAXReader saxReader = new SAXReader();
if (isSchemaValidating()) {
saxReader.setEntityResolver(new DTDEntityResolver());
saxReader.setValidation(true);
saxReader.setFeature("http://apache.org/xml/features/validation/sche...;
}
saxReader.setMergeAdjacentText(true);
elements.put(fileInputStream.getKey(),
saxReader.read(fileInputStream.getValue()).getRootElement());
} catch (DocumentException dex) {
Throwable nested = dex.getNestedException();
if (nested != null) {
if (nested instanceof FileNotFoundException) {
throw new RuntimeException(
"Can't find schema/DTD reference for file:
"
+ fileInputStream.getKey() + "': "
+ nested.getMessage(), dex
);
} else if (nested instanceof UnknownHostException) {
throw new RuntimeException(
"Cannot connect to host from schema/DTD reference:
"
+ nested.getMessage()
+ " - check that your schema/DTD reference is
current", dex
);
}
}
throw new RuntimeException("Could not parse XML file: " +
fileInputStream.getKey() ,dex);
} catch (Exception ex) {
throw new RuntimeException("Could not parse XML file: " +
fileInputStream.getKey() ,ex);
}
I can use that with the classpath:// feature of the DTDEntityResolver (which is the same
as in Hibernate):
<?xml version="1.0" encoding="UTF-8"?>
<plugin key="hw" label="Hello World"
xmlns="http://jboss.com/products/seam/wiki/plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.com/products/seam/wiki/plugin
classpath://org/jboss/seam/wiki/core/plugin/plugin-1.0.xsd">
...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: