[xml] RelaxNG, xmlTextReader, and streaming error



Well, I've managed to narrow down the conditions under which using an
xmlTextReader with RelaxNG schema validation fails.

First of all, I have a brand-new hot off the presses build of libXML2
installed.

I've also cleaned up my RelaxNG schema and have my test document
validating under xmllint, both with the RelaxNG schema and a DTD generated
from that schema by trang, in both normal mode and in streaming mode.

Now, my program is still failing IF I use RelaxNG - it is still asserting
that nodes it just read are not in the XML.

However, it works fine using the DTD.

What I am doing is repeatedly calling xmlTextReaderRead() to move from
node to node, processing them as they come in. I am not explicitly freeing
the nodes or anything like that - I am letting the reader free the nodes
when it thinks it is appropriate. The RelaxNG validation error happens
when I move to the next node after an XML_READER_TYPE_END_ELEMENT.

Now, for testing I put in a call to xmlTextReaderPreserve() every time I
encounter an XML_READER_TYPE_ELEMENT node. This leaks memory like a sieve
and wouldn't work for my eventual application, but it did allow me to test
the hypothesis that the nodes were being freed too soon.

With that call in place my code validates my document. Without that call,
it does not.

So the xmlTextReader is freeing child nodes of a parent too soon under
certain circumstances, and then when it tries to validate the parent, it
is not finding what is required by the schema and failing.

Since the xmlTextReader doesn't seem to have a public means to let me see
the parser, I cannot easily instrument the parser to find out what logic
it uses to determine when to throw nodes away.

Since xmllint works and my code does not, it would seem that I am doing
"something wrong" - is it not valid to walk the stream using
xmlTextReaderRead() if you are wanting to do RelaxNG validation?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]