The implementation of NVDL does something very similar to what you want to do: it uses the RELAX NG schema to validate the NVDL schema while at the same time building its internal representation of the schema.
Let's call your ContentHandler that populates the hash-table B. Le'ts call your error handler that reports errors E. First of all you create a wrapper E' around E. E' just keeps track of whether there's been an error before forwarding the error event on to E. Now create a Validator V that uses E' as it's ErrorHandler. Now create a ContentHandler C, that has references to B, V, and E'. This forwards each event to V. It then checks E' to see whether there's been an error. If there hasn't been an error, it then forwards the event also to B. Hope this helps. James On Wed, Apr 8, 2009 at 7:50 PM, mr_xsive <[email protected]> wrote: > Hi, > > I have an XML file which I'd like to validate. I also want to populate a > hash table based on the contents of the document -- ideally at the same > time. > > Long story short: I've setup a validation routine similar to JING's > ValidationDriver. What I now want to do is this: if an element is valid, I'd > like to perform some application logic based on its contents and populate my > hash table. > > However, I can't extend the Validator object because it gets created by my > Schema object and there's no (easy) way I can tell it to construct a > different validator. > > If I try to construct my own Validator it turns into a real nightmare as I > then need a Pattern object for the constructor and understanding how to > build one of those requires diving into the internals of JING (I spent an > hour or so tracing through the code but eventually gave up). > > So I thought, OK, no problem. I'll just create a new proxy ContentHandler > which encapsulates one of JING's Validators and pass that to my XMLReader. I > figured each time one of my ContentHandler methods is invoked I can invoke > the JING's Validator method of the same name and thus check if the element > is valid before I perform my stuff. > > But I'm foiled again because JING's Validators implement not just the > ContentHandler interface but also ErrorHandler so I never know if there was > an error or not because the startElement method (for instance) calls > directly to the error method. > > Since there's no separation of concerns between handling the content and > dealing with errors I'm left with no real option except to parse the > document once for validity and then parse it again with a custom > ContentHandler to do my stuff. > > Is there any way out of this mess? > > > > ------------------------------------ > > Yahoo! Groups Links > > > >
