You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Scott Carter <sc...@dotsconnect.com> on 2001/01/29 17:16:53 UTC

Can't get Xerces to validate

I am using the following code to validate a document, but it does not seem
to be detecting any errors?


try {
		DOMParser parser = new DOMParser();

		parser.setFeature("http://xml.org/sax/features/validation", true);
		parser.setFeature("http://apache.org/xml/features/validation/dynamic",
true);
		parser.setFeature("http://apache.org/xml/features/validation/schema",
true);

		parser.parse(new InputSource(stream)); //stream is a valid InputStream
		document = parser.getDocument();

	} catch (SAXParseException pe) {
		// Error generated by the parser
		String errMsg = "\n** Parsing error" + ", line "
						+ pe.getLineNumber() + ", uri "
						+ pe.getSystemId() + "\n"
						+ pe.getMessage();
		new Error(errMsg, Error.SEVERITY_FATAL);
		throw new XmlDocumentException(errMsg);
	} catch (SAXException sax) {
		String errMsg = "Unable to create XML document: " + sax.getMessage();
		new Error(errMsg, Error.SEVERITY_FATAL);
		throw new XmlDocumentException(errMsg);
	} catch (IOException ioe) {
		String errMsg = "Unable to create XML document: " + ioe.getMessage();
		new Error(errMsg, Error.SEVERITY_FATAL);
		throw new XmlDocumentException(errMsg);
	}

Does anyone know what I'm doing wrong here?

Scott Carter


Re: Can't get Xerces to validate

Posted by Christer Evenius <ch...@cybercom.se>.
Hi, Scott!

As far as I can see you have not set the ErrorHandler...
:
:
parser.setErrorHandler( new ErrorHandlerImpl() );
:
:
class ErrorHandlerImpl implements ErrorHandler {
    public void warning( SAXParseException ex ) {
    }
    public void error( SAXParseException ex ) {
    }
    public void fatalError( SAXParseException ex ) throws SAXException {
    }

Regards Christer Evenius

----- Original Message -----
From: "Scott Carter" <sc...@dotsconnect.com>
To: <xe...@xml.apache.org>
Sent: Monday, January 29, 2001 5:16 PM
Subject: Can't get Xerces to validate


> I am using the following code to validate a document, but it does not seem
> to be detecting any errors?
>
>
> try {
> DOMParser parser = new DOMParser();
>
> parser.setFeature("http://xml.org/sax/features/validation", true);
> parser.setFeature("http://apache.org/xml/features/validation/dynamic",
> true);
> parser.setFeature("http://apache.org/xml/features/validation/schema",
> true);
>
> parser.parse(new InputSource(stream)); //stream is a valid InputStream
> document = parser.getDocument();
>
> } catch (SAXParseException pe) {
> // Error generated by the parser
> String errMsg = "\n** Parsing error" + ", line "
> + pe.getLineNumber() + ", uri "
> + pe.getSystemId() + "\n"
> + pe.getMessage();
> new Error(errMsg, Error.SEVERITY_FATAL);
> throw new XmlDocumentException(errMsg);
> } catch (SAXException sax) {
> String errMsg = "Unable to create XML document: " + sax.getMessage();
> new Error(errMsg, Error.SEVERITY_FATAL);
> throw new XmlDocumentException(errMsg);
> } catch (IOException ioe) {
> String errMsg = "Unable to create XML document: " + ioe.getMessage();
> new Error(errMsg, Error.SEVERITY_FATAL);
> throw new XmlDocumentException(errMsg);
> }
>
> Does anyone know what I'm doing wrong here?
>
> Scott Carter
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Can't get Xerces to validate

Posted by Milind Gadre <mi...@ecplatforms.com>.
Scott, you need to associate a ErrorHandler with the parser. For maximum
conformance, throw all exceptions, including warning, error and
fatalError.

Regards...

Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com

----- Original Message -----
From: "Scott Carter" <sc...@dotsconnect.com>
To: <xe...@xml.apache.org>
Sent: Monday, January 29, 2001 8:16 AM
Subject: Can't get Xerces to validate


> I am using the following code to validate a document, but it does not
seem
> to be detecting any errors?
>
>
> try {
> DOMParser parser = new DOMParser();
>
> parser.setFeature("http://xml.org/sax/features/validation", true);
> parser.setFeature("http://apache.org/xml/features/validation/dynamic",
> true);
> parser.setFeature("http://apache.org/xml/features/validation/schema",
> true);
>
> parser.parse(new InputSource(stream)); file://stream is a valid
InputStream
> document = parser.getDocument();
>
> } catch (SAXParseException pe) {
> // Error generated by the parser
> String errMsg = "\n** Parsing error" + ", line "
> + pe.getLineNumber() + ", uri "
> + pe.getSystemId() + "\n"
> + pe.getMessage();
> new Error(errMsg, Error.SEVERITY_FATAL);
> throw new XmlDocumentException(errMsg);
> } catch (SAXException sax) {
> String errMsg = "Unable to create XML document: " + sax.getMessage();
> new Error(errMsg, Error.SEVERITY_FATAL);
> throw new XmlDocumentException(errMsg);
> } catch (IOException ioe) {
> String errMsg = "Unable to create XML document: " + ioe.getMessage();
> new Error(errMsg, Error.SEVERITY_FATAL);
> throw new XmlDocumentException(errMsg);
> }
>
> Does anyone know what I'm doing wrong here?
>
> Scott Carter
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>


Re: SystemID sent to EntityResolver contains absolute path

Posted by Milind Gadre <mi...@ecplatforms.com>.
Brad, I found this behavior to be extremely annoying also. The
documentation states that the system id in the document is converted to
a url format *before* handing off to the entity resolver. It is unclear
why it cannot be passed in as is also, maybe as a 3rd parameter. Or
better still, have a prior step where a 'URLConverter' class decides how
it is to be converted instead of applying a hardcoded rule blindly.

For your specific situation (which was similar to what I wanted), I
ended up using a PUBLIC identifier, and leaving the system id empty. I
then used this logic

1. if the system id is empty, look up the dtd from a known location
based on the public id

2. else, we have a fully specified dtd url, so let the default mechanism
handle it

Hope this helps ....

Regards...

Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com

----- Original Message -----
From: "Brad O'Hearne" <ca...@megapathdsl.net>
To: <xe...@xml.apache.org>
Sent: Thursday, February 15, 2001 7:13 AM
Subject: SystemID sent to EntityResolver contains absolute path


> Hello all,
>
> I am using an EntityResolver to resolve the proper value for my DTD
referred
> to in my xml file.  I have no path in the xml file, just the dtd name,
i.e.
> "brad.dtd".  However, when the resolveEntity method is called, the
value
> passed to the publicId parameter is NULL and the value passed to the
> systemId parameter is not simply "brad.dtd", but something like the
> following: "file:///data/dev/brad.dtd".  Is there any way just to
receive
> the actual value in the xml file, "brad.dtd"?
>
> Brad
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>


SystemID sent to EntityResolver contains absolute path

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
Hello all,

I am using an EntityResolver to resolve the proper value for my DTD referred
to in my xml file.  I have no path in the xml file, just the dtd name, i.e.
"brad.dtd".  However, when the resolveEntity method is called, the value
passed to the publicId parameter is NULL and the value passed to the
systemId parameter is not simply "brad.dtd", but something like the
following: "file:///data/dev/brad.dtd".  Is there any way just to receive
the actual value in the xml file, "brad.dtd"?

Brad


Re: How to create a validating SAXParser?

Posted by Ian Roberts <ir...@decisionsoft.com>.
On Thu, 8 Feb 2001, Brad O'Hearne wrote:

> Hello all,
> 
> Got an easy question for you.  In SAX2, I want to manipulate the features
> and properties of the parser that I create (like making an instance of a
> SAXParser a validating parser).  Is there anywhere that I can find a global
> listing of all of the supported features and/or properties that the
> SAXParser recognizes?  I read in the API docs the following:

http://xml.apache.org/xerces-j/features.html

Ian

-- 
Ian Roberts, Software Engineer        DecisionSoft Ltd.
tel: +44-1865-203192                  http://www.decisionsoft.com


How to create a validating SAXParser?

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
Hello all,

Got an easy question for you.  In SAX2, I want to manipulate the features
and properties of the parser that I create (like making an instance of a
SAXParser a validating parser).  Is there anywhere that I can find a global
listing of all of the supported features and/or properties that the
SAXParser recognizes?  I read in the API docs the following:

"XMLReaders are not required to recognize setting any specific property
names, though a core set is provided with SAX2."

Where can I find this core set?

(Actually, my question is really how to set my parser to validating mode,
but I am also curious about the other options I can manipulate in the
parser.)

Thanks in advance.

Brad