[jdom-interest] Schema Validation [newbie question]

Kohler, Holger Holger.Kohler at dsto.defence.gov.au
Mon Jul 9 17:23:13 PDT 2001


Hello all,

I've been trying to test out schema validation using JDOM-b7 and xerces
1.4.1 with no success. I've been working against the standard test files
"catalog.xml" and even "personal-schema.xml" from the xerces-j install and I
keep getting the following style of error message whenever I turn validation
on (using the SAXBuilder constructor or the setValidation(true) method).

>java -classpath ..\jdom.jar samples.SAXBuilderDemo personal-schema.xml
org.xml.sax.SAXParseException: Element type "personnel" must be declared.
        at
org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1008)
        at
org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(X
MLValidator.java:1236)
        at
org.apache.xerces.validators.common.XMLValidator.validateElementAndAttribute
s(XMLValidator.java:2673)
        at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidat
or.java:818)
        at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanne
r.java:1852)
        at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
LDocumentScanner.java:1000)
        at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
java:380)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:287)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:682)
        at samples.SAXBuilderDemo.main(SAXBuilderDemo.java:114)

When I run the xerces sample SAXCount with validation turned on it works
fine.... 

>java -classpath xercesSamples.jar;xerces.jar dom.SAXCount -v
data\personal-schema.xml
data\personal-schema.xml: 571 ms (37 elems, 20 attrs, 140 spaces, 128 chars)

When I use the -N option to turn namespaces off I get very similar errors to
the above.
>java -classpath xercesSamples.jar;xerces.jar sax.SAXCount -v -N
data\personal-schema.xml
[Error] personal-schema.xml:3:50: Element type "personnel" must be declared.
[Error] personal-schema.xml:5:26: Element type "person" must be declared.
[Error] personal-schema.xml:6:11: Element type "name" must be declared.
[Error] personal-schema.xml:6:19: Element type "family" must be declared.
[Error] personal-schema.xml:6:41: Element type "given" must be declared.

My best guess is that it is namespace related because that is the flag I
change to get the xerces sample to work. Is there a way to call the 
XMLReader.setFeature("http://xml.org/sax/features/namespaces", true); from
JDOM because this seems to be the effect of the -N flag in the xerces
example? The SAXBuilder has a setValidation method, could it also have a
setNamespaces method? Does anyone else thing this would fix my problem?

Regards,

Holger Kohler






More information about the jdom-interest mailing list