Re: [xml] help with xmlTextReaderRead (with DTD validation)



On Tue, Jul 29, 2008 at 07:31:27AM -0400, Denis Bourgeois wrote:

Although I have contributed to a few (free) scientific applications
(in C and F77) for quite some time, I'm new to xml and libxml2 (this may
explain the naiveté of my question): I'm writing a C parser for an XML
input (input only, no file editing or writing out) - so the xmlTextReader
API (http://xmlsoft.org/xmlreader.html#L1142) seems very appropriate. I
have gone through the tutorial and am now in the process of integrating
DTD validation. The DTD validation correctly flags errors, but I can't
seem to add appropriate code to halt the scanning process once a first
parsing error occurs (the code below - lightly adapted from the tutorial -
simply goes on and on, parsing the entire file despite the initial DTD
parsing errors): --- C code ---

  That's normal. DTD validation error are not fatal errors, so from
a parsing viewpoint it's normal to continue processing.
  Add an xmlTextReaderIsValid() test in your reading loop and break if
it returns a value != 1

once a first parsing error occurs? Question 2: The screen output indicates
that the DTD error (lines 7. versus 12.) is immediately flagged after
the first xmlTextReaderRead call (line 24.); if the xmlTextReader only
scans one element node at a time, how can it initially flag this error
(which only occurs later)? Is it building an entire DOM tree to do

  No the reader builds a sliding subset of the tree as it progresses,
unless of course your document is tiny it will never be fully loaded in
memory.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



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