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 Phil Weighill-Smith <ph...@volantis.com> on 2004/02/23 10:42:39 UTC
Re: Validation with external-noNamespaceSchemaLocation works with
DTD, not with xsd schema
Have you tried enabling the
"http://apache.org/xml/features/validation/schema" feature?
Phil :n.
On Mon, 2004-02-23 at 09:26, Pander wrote:
> Hi all,
>
> Validation (SAX and DOM) with external-noNamespaceSchemaLocation works with
> DTD, not with xsd schema (xerces 2.6.1).
>
> The following code bails out with an error on xsd schema but works fine with
> DTD. Problem is that with xsd, it does not realise that it has to deal with
> xsd, hence the error as can be seen below.
>
> Is this a bug or what has to be changed in the code to get this working?
>
> code
> ----
> import org.apache.xerces.parsers.DOMParser;
> import org.w3c.dom.Document;
>
> class validate {
> public static void main(String[] args) {
> try {
> DOMParser aParser = new DOMParser();
> aParser.setFeature
> ("http://xml.org/sax/features/validation", true);
> aParser.setFeature
> ("http://apache.org/xml/features/continue-after-fatal-error", false);
> aParser.setFeature
> ("http://apache.org/xml/features/validation/schema-full-checking", true);
> aParser.setProperty
> ("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
> args[1]);
> aParser.parse(args[0]);
> } catch (Exception e) {
> System.err.println("Exception caught in main: " +e);
> System.exit(1);
> }
> }
> }
>
> compile
> -------
> javac -classpath xercesImpl.jar:xmlParserAPIs.jar validate.java
>
> files used in the next tests are from Xerces-J-bin.2.6.1.tar.gz from data
> directory
>
> correct run with DTD
> --------------------
> java -classpath .:xercesImpl.jar:xmlParserAPIs.jar validate personal.xml
> personal.dtd
>
> incorrect run with xsd schema
> -----------------------------
> java -classpath .;xercesImpl.jar;xmlParserAPIs.jar validate personal-
> schema.xml personal.xsd
>
> [Error] personal.xml:2:11: Document is invalid: no grammar found.
> [Error] personal.xml:2:11: Document root element "personnel", must match
> DOCTYPE root "null".
>
> As mentioned before this code is not aware that it has to deal with xsd
> schema instead of DTD. How can this be fixed since the code example is in a
> lot of tutorials on the net.
>
> Thanks,
>
> Pander
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
--
Phil Weighill-Smith <ph...@volantis.com>
Volantis Systems