You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Oliver, Steve" <St...@bestwestern.com> on 2003/03/18 19:16:58 UTC

Validation with ApplyXPath Sample

Hi,

I'm just getting started with Xalan-J 2.5 by running the samples. Specifically, I'm trying to use the ApplyXPath sample with one minor change. I would like to use a validating parser. I've turned validation on

DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
dfactory.setValidating(true);

then created a schema for the sample foo.xml called foo.xsd and modified foo.xml to reference it.

<?xml version="1.0"?>
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
	<name first="David" last="Marston"/>
	<name first="David" last="Bertoni"/>
	<name first="Donald" last="Leslie"/>
	<name first="Emily" last="Farmer"/>
	<name first="Joseph" last="Kesselman"/>
	<name first="Myriam" last="Midy"/>
	<name first="Paul" last="Dick"/>
	<name first="Stephen" last="Auriemma"/>
	<name first="Scott" last="Boag"/>
	<name first="Shane" last="Curcuru"/>
</doc>

I have not added an error handler, assuming for now that the default will be okay. Here is the result...

Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired.  Parser will use a default
ErrorHandler to print the first 10 errors.  Please call
the 'setErrorHandler' method to fix this.
Error: URI=null Line=2: Document is invalid: no grammar found.
Error: URI=null Line=2: Document root element "doc", must match DOCTYPE root "null".
Querying DOM using //name[@first='David']
<output>
<name first="David" last="Marston"/>
<name first="David" last="Bertoni"/>
</output>

Both the schema and the xml document validate fine with XMLSpy so I don't believe there is anything wrong with either.

Am I missing something simple here? What is the error?

Steve