Re: [xml] Validating a previously validated and then modified document

Date view Thread view Subject view Author view

From: Gary Pennington (Gary.Pennington@uk.sun.com)
Date: Wed Feb 07 2001 - 11:18:10 EST


Daniel Veillard wrote:

> On Wed, Feb 07, 2001 at 02:49:50PM +0000, Gary Pennington wrote:
> >
> > Hi,
> >
> > I have a document with an associated DTD. I validate it. I then
> > programmatically make changes to the document, including adding new
> > elements, updating attributes, etc...
> >
> > Now, before I write the document to disk I want to re-validate the
> > document to ensure that it is still valid and no errors have been
> > introduced. How to do this in libxml?
> >
> > I tried calling xmlValidateDocument,
>
> yes, that's the right way,
>
> > however it complained that IDs were
> > already defined which means, I guess, that the data structures are still
> > there from the previous validation and thus causing problems for the
> > re-validation.
> >
> > I did a quick hack to set ids and refs to NULL in the document when
> > calling xmlValidateDocument and this did the trick for me at the cost of
> > a memory leak.
> >
> > I think the real answer is to find the core validation function(s) and
> > do an xmlFreeIDTable and an xmlFreeRefTable whenever validation is
> > called if the table pointers aren't null.
>
> Right this should be done only at revalidation time.
>
> > I'm not certain that this patch is catching all areas where it's
> > required, so it needs some scrutiny. It's working fine for me in the
> > scenario I descrbed above. I decided to put the check in xmlValidateRoot
> > since I was pretty sure that this would be called whenever an entire
> > document was validated, however it may be the wrong place for this
> > check.
>
> Yes I'm afraid that you would loose ID and REF tables when parsing
> and validating at the very last step of the document validation, I'm
> not 100% sure about this but I would prefer to avoid the risk :-).
> This should be added only when one is about to revalidate a document.
> So I added it at the beginning of xmlValidateDocument() and
> xmlValidateDtd().
> Patch enclosed, quick feedback on it would be welcome,

I think you are correct. I just checked to see where xmlValidateRoot was
called from and the calls from xmlParseElement and startElement and
xmlParseTryOrFinish would yield the undesired effect of blowing away ids and
refs.

Your amendment appears correct.

Gary

>
>
> Daniel
>
> --
> Daniel Veillard | Red Hat Network http://redhat.com/products/network/
> veillard@redhat.com | libxml Gnome XML toolkit http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
>
> ------------------------------------------------------------------------
>
> valid.diffName: valid.diff
> Type: Plain Text (text/plain)

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Feb 07 2001 - 12:48:40 EST