You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Milan Tomic <to...@yahoo.com> on 2006/04/21 11:51:00 UTC
Schema validation error
After few hours spent on searching the Internet, I decided to ask this question here.
I have code that validates document using schema:
public static void validate(InputStream _xml, String _schemaLocation) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", _schemaLocation);
ErrorHandler eh = new XMLSchema.MyErrorHandler();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(eh);
Document doc = db.parse(_xml);
}
Above code usually works fine, but under OC4J application server it fails with message:
06/04/21 09:25:37 java.lang.IllegalArgumentException:
http://java.sun.com/xml/jaxp/properties/schemaLanguage
06/04/21 09:25:37 at
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:118)
I suppose it is using some older version of Xerces (don't know which). I've tried to set schema
validation file (.xsd) in the older fashioned way:
public static void validate(InputStream _xml, String _schemaLocation) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute("http://apache.org/xml/properties/schema/external-schemaLocation",
_schemaLocation);
ErrorHandler eh = new XMLSchema.MyErrorHandler();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(eh);
Document doc = db.parse(_xml);
}
But then I got:
Exception in thread "main" org.xml.sax.SAXParseException: Document is invalid: no grammar found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
What should I do? :(
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Schema validation error
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Milan Tomic <to...@yahoo.com> wrote on 04/21/2006 05:56:34 AM:
>
> If I set schema validation like this:
>
> dbf.setFeature("http://apache.org/xml/features/validation/schema",
true);
>
> then I got:
>
> Exception in thread "main" java.lang.NoSuchMethodError:
>
javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
Not surprising if you're using a much older version of Xerces.
DocumentBuilderFactory.setFeature() has only existed since JAXP 1.3
(Xerces 2.7.0+). You could try dbf.setAttribute("
http://apache.org/xml/features/validation/schema", Boolean.TRUE); instead.
> :(
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Schema validation error
Posted by Milan Tomic <to...@yahoo.com>.
If I set schema validation like this:
dbf.setFeature("http://apache.org/xml/features/validation/schema", true);
then I got:
Exception in thread "main" java.lang.NoSuchMethodError:
javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
:(
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org