You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Steve Byrne <sb...@penguinis.org> on 2003/08/07 08:53:08 UTC

[Digester] XML driven schema validation?

I'm trying to get digester to do XML Schema validation based off the schema
referenced in the input XML file.  I have tried doing
digester.setSchema("foo.xsd"), and that works, but I want to have the schema
used for validation instead be selected by the incoming XML file.  

I've tried doing digester.setSchemaLanguage to try to force the use of W3C XML
Schema style schema definitions, and a number of other things, but they all
produce a result that's identical to having no DTD present and validation
turned on (something about root element should be null, doesn't match DOCTYPE,
etc).

I'm using digester 1.5 and it's recommended versions of other jakarta
packages.  I am using J2SDK 1.4.1, which I *think* has JAXP 1.1+ in it (it's
hard to determine for sure; I thougth I saw one document saying that it has
JAXP 1.1.3 included in it, so that's beyond the digester site recommendation of
JAXP 1.1).

Is there a known deficiency with digester in this area?  Is there some
non-obvious trick that I have to do to get digester to pay attention to the
schema namespace and declarations in the input XML file?

Steve

Re: [Digester] XML driven schema validation?

Posted by Steve Byrne <sb...@penguinis.org>.
Simon Kitching <si...@ecnetwork.co.nz> writes:

> 
> What are you seeing as your behaviour? A hang, or just invalid documents
> being processed?

The behavior [our economic conditions prevent us from spending extra money on
adding the additional "U"] that I'm seeing is precisely that you'd get if you
turned on validation and didn't have a <!DOCTYPE > declaration in the page. 

It says something about invalid root element, was expecting "null" but got
"modules" or whatver the root element in the input document is.


> Hmm.. I wonder what default ErrorHandler the Digester sets up for its
> parser...
> 
> One solution for you that will *definitely* work is for you to create a
> validating SAXParser object yourself, using the normal JAXP apis, pass
> the Digester object as the SAX Content Handler (digester implements this
> interface) then call parse on the SAX parser object. This way, you have
> the responsibility of setting up the parser exactly as you wish. Well,
> by "definitely work", I mean that the responsibility for setting up the
> parser to do validation is now yours, not the digester's.

Right -- that will work alright.  Still, it would be nice to know definitively
if digester cannot support the behavior outlined, and if so, the docs should be
clear on the usage of the setSchema method and what it implies. 

Thanks for the suggestions!!!

Steve


Re: [Digester] XML driven schema validation?

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Fri, 2003-08-08 at 04:04, Steve Byrne wrote:
> Simon Kitching <si...@ecnetwork.co.nz> writes:
> 
> Ki ora, Simon ;)

:-)

What are you seeing as your behaviour? A hang, or just invalid documents
being processed?

Hmm.. I wonder what default ErrorHandler the Digester sets up for its
parser...

One solution for you that will *definitely* work is for you to create a
validating SAXParser object yourself, using the normal JAXP apis, pass
the Digester object as the SAX Content Handler (digester implements this
interface) then call parse on the SAX parser object. This way, you have
the responsibility of setting up the parser exactly as you wish. Well,
by "definitely work", I mean that the responsibility for setting up the
parser to do validation is now yours, not the digester's.


Cheers,

Simon


> 
> Yes, it's good that you asked about this since I didn't specify it in my
> query.  Right after instantiating the digester instance, I called:
> 
>    digester.setNamespaceAware(true);
>    digester.setValidating(true);
> 
>    // with or without this line, the behavior is the same.  I may not
>    // have the URL exactly right here; this is from memory and not
>    // cut & pasted from the actual code
>    digester.setSchemaLanguage("http://www.w3.org/XMLSchema");
> 
> 
> > Hi,
> > 
> > Sorry to ask the obvious, but have you called
> >   digester.setValidating(true)
> > immediately after creating the digester instance?
> > 
> > On Thu, 2003-08-07 at 18:53, Steve Byrne wrote:
> > 
> > > I'm trying to get digester to do XML Schema validation based off the schema
> > > referenced in the input XML file.  I have tried doing
> > > digester.setSchema("foo.xsd"), and that works, but I want to have the schema
> > > used for validation instead be selected by the incoming XML file.  
> > 
> > 
> > 
> 
> 


Re: [Digester] XML driven schema validation?

Posted by Steve Byrne <sb...@penguinis.org>.
Simon Kitching <si...@ecnetwork.co.nz> writes:

Ki ora, Simon ;)

Yes, it's good that you asked about this since I didn't specify it in my
query.  Right after instantiating the digester instance, I called:

   digester.setNamespaceAware(true);
   digester.setValidating(true);

   // with or without this line, the behavior is the same.  I may not
   // have the URL exactly right here; this is from memory and not
   // cut & pasted from the actual code
   digester.setSchemaLanguage("http://www.w3.org/XMLSchema");


> Hi,
> 
> Sorry to ask the obvious, but have you called
>   digester.setValidating(true)
> immediately after creating the digester instance?
> 
> On Thu, 2003-08-07 at 18:53, Steve Byrne wrote:
> 
> > I'm trying to get digester to do XML Schema validation based off the schema
> > referenced in the input XML file.  I have tried doing
> > digester.setSchema("foo.xsd"), and that works, but I want to have the schema
> > used for validation instead be selected by the incoming XML file.  
> 
> 
> 


Re: [Digester] XML driven schema validation?

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi,

Sorry to ask the obvious, but have you called
  digester.setValidating(true)
immediately after creating the digester instance?

On Thu, 2003-08-07 at 18:53, Steve Byrne wrote:

> I'm trying to get digester to do XML Schema validation based off the schema
> referenced in the input XML file.  I have tried doing
> digester.setSchema("foo.xsd"), and that works, but I want to have the schema
> used for validation instead be selected by the incoming XML file.