Re: [xml] Getting the offset of a node in the stream

On Fri, Aug 07, 2009 at 04:23:15PM +0300, Alberto Mardegan wrote:
  I'm using an xmlTextReader (and the xmlTextReaderNext() function) to
read an XML file, and once I find a specific element I must be able to
tell at what byte offset in the file this element is found.
The API has a xmlTextReaderByteConsumed() function that according to
the docs seems to do what I want, but in fact it doesn't, because it
returns the offset of a few elements ahead.

Is there a method to obtain the exact offset of an element?

  No. All you can get is at what point the parser is at that given
time. If using SAX (which I don't suggest) then you get something
relatively precise, but it can be extremely costly. For the reader
it progresses by chunk and what you get is the end of the latest parsed
chunk (hence ahread of the current node).

  In general looking for the offset is just the wrong way to proceed,
XML is structured data, and the best addressing parttern is tu use
the structure (XPath/XPointer), anything else will give poor or costly/
unprecise results.


Daniel Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

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