Re: [xml] Parsing <?xml decl with xmlReader

On Tue, Nov 15, 2005 at 11:17:05AM +1100, Michael Day wrote:


The xmlReaderTypes enumeration contains this value:


However it seems that this value is never returned to the caller, and it
does not seem to be used anywhere in the libxml2 code.

  I think we matched microsoft XMLReader behaviour on this.

Is it possible to tell whether or not an <?xml...?> declaration was parsed
when using the xmlReader?

  if there is a doc->encoding or doc->standalone != -1 then there was a
declaration for sure, but otherwise one just can't tell.

(There is a function to get the XML version number from the current
document; if that returns NULL, does it indicate that there was no XML
declaration parsed?)

If not, is it possible to tell when using the SAX parser?

  No because the code parsing it in xmlParseXMLDecl() does not fire any
SAX event, so any proof of having gone though that path can only be noticed
by the side effects of that routine. It sets ctxt->version, so if you
don't have ctxt->version you can be sure you didn't had an XMLDecl, but
unfortunately I documents are alway created with a version string of 1.0
if no XMLDecl is found, see line 9081 of parser.c


Daniel Veillard      | Red Hat
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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