Re: Validation with external-noNamespaceSchemaLocation works with
DTD, not wit 2004-02-23 - By Phil Weighill-Smith
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@(protected) > For additional commands, e-mail: xerces-j-user-help@(protected)
-- Phil Weighill-Smith <phil.weighill-smith@(protected)> Volantis Systems
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8"> <META NAME="GENERATOR" CONTENT="GtkHTML/3.0.9"> </HEAD> <BODY> Have you tried enabling the "http://apache.org/xml/features/validation /schema" feature?<BR> <BR> Phil :n.<BR> <BR> On Mon, 2004-02-23 at 09:26, Pander wrote: <BLOCKQUOTE TYPE=CITE> <PRE><FONT COLOR="#737373"><I>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 ("</FONT><A HREF="http://xml.org/sax/features/validation"><U>http://xml .org/sax/features/validation"</U></A><FONT COLOR="#737373">, true); aParser.setFeature ("</FONT><A HREF="http://apache.org/xml/features/continue-after-fatal -error"><U>http://apache.org/xml/features/continue-after-fatal-error"</U>< /A><FONT COLOR="#737373">, false); aParser.setFeature ("</FONT><A HREF="http://apache.org/xml/features/validation/schema-full -checking"><U>http://apache.org/xml/features/validation/schema-full-checking "</U></A><FONT COLOR="#737373">, true); aParser.setProperty ("</FONT><A HREF="http://apache.org/xml/properties/schema/external -noNamespaceSchemaLocation"><U>http://apache.org/xml/properties/schema/external -noNamespaceSchemaLocation"</U></A><FONT COLOR="#737373">, 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@(protected) For additional commands, e-mail: </FONT><A HREF="mailto:xerces-j-user-help@(protected) .apache.org">xerces-j-user-help@(protected)</I></A></PRE> </BLOCKQUOTE> <PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%"> <TR> <TD> -- <BR> Phil Weighill-Smith <<A HREF="mailto:phil.weighill-smith@(protected)"><U >phil.weighill-smith@(protected)</U></A>><BR> Volantis Systems </TD> </TR> </TABLE> </PRE> </BODY> </HTML>
|
|