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 ro...@elastica.com on 2005/09/01 00:28:21 UTC
Re: Validation with Xerces
Do you need to use apache specific feature uris?
see http://xml.apache.org/xerces2-j/features.html
Quoting Rich Knox <ri...@dreamflying.com>:
>
>
>
>
>
>
>
> I have code that runs successfully against the Crimson XML parser
> provided with JDK 1.4. I'm having problems getting it to run correctly
> against the Xerces parser provided in JDK 1.5. We have a DTD we wish to
> validate against. When I run this code against Crimson, everything
> works as expected. When I try to run it against Xerces, the parser does
> not appear to be doing any validation against our DTD. If I make the
> XML badly formed, I get an error in Crimson but not Xerces. Is there
> something special I need to do to enable validation with Xerces that
> was not required with Crimson? Here is a simplified version (error
> handling removed) of the code we use to create and configure the parser:
>
>
>
> SAXParserFactory factory;
>
> SAXParser parser;
>
> XMLReader reader;
>
>
>
> factory = SAXParserFactory.newInstance();
>
> factory.setValidating(true);
>
>
>
> parser = factory.newSAXParser();
>
> reader = parser.getXMLReader();
>
>
>
> // handler is an instance of a class that extends DefaultHandler
>
> reader.setContentHandler(handler);
>
> reader.setDTDHandler(handler);
>
> reader.setErrorHandler(handler);
>
> reader.setEntityResolver(handler);
>
>
>
> // Set these features explicitly as opposed to relying on their
>
> // default values to deal with differences between various
>
> // crimson and xerces releases. setReaderFeature is a wrapper
>
> // wrapper that catches exceptions and return a boolean
> indicating
>
> // success or failure
>
> setReaderFeature(reader,
> "http://xml.org/sax/features/validation", true);
>
> setReaderFeature(reader,
> "http://xml.org/sax/features/namespaces", true);
>
> setReaderFeature(reader,
> "http://xml.org/sax/features/namespace-prefixes", false);
>
>
>
> // Register for lexical events so that we are notified of
>
> // comments.
>
> if (!setReaderProperty(reader,
> "http://xml.org/sax/properties/lexical-handler", this))
>
> {
>
> // If the previous property "set" failed, try the same
> operation
>
> // with a different version of the property name.
>
> setReaderProperty(reader,
> "http://xml.org/sax/handlers/LexicalHandler", this);
>
> }
>
>
>
> I also tried using XMLReaderFactory instead of SAXParserFactory and got
> the same results (no validation in Xerces). What do I need to do to get
> Xerces to validate? Thanks.
>
>
>
> -rich
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org