Re: [xml] xmlTextReaderReadOuterXml and xmlTextReaderReadInnerXml


I can't take too much credit for the code that is here, I went searching
for implimentations of these two functions and found them here:

The code that was in HEAD for xmlreader.c did not work on my first try, the
function xmlTextReaderSkip() seems to break the xmlTextReaderOuterXml()

Here is a modified version of the xmlTextReaderOuterXml() function
addressing some of the changes you suggested:
The new version does not allocate a new doc, and it uses the buff->content
as the return instead of allocating a new one.

xmlChar *
xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
    xmlChar *                           resbuf;
    xmlNodePtr                          node;
    xmlBufferPtr                        buff;
    xmlDocPtr                           doc;

    node = reader->node;
    doc = reader->doc;
    node = xmlDocCopyNode(node, doc, 1);
    buff = xmlBufferCreate();
    xmlNodeDump(buff, doc, node, 0, 0);

    resbuf = buff->content;
    buff->content = NULL;

    return resbuf;

You were right, the xmlTextReaderInnerXml() function was the same as the
outer one, that was my fault, I screwed up the copy/paste.  I'm trying to
get it working, but I'm new to the libxml APIs besides the reader API, so
there is a lot of investigation on my part going on.


James Wert Jr.
JWert ILSTechnology com

|         |           Daniel Veillard  |
|         |           <veillard redhat |
|         |           com>             |
|         |                            |
|         |           05/23/2005 04:33 |
|         |           AM               |
|         |           Please respond to|
|         |           veillard         |
  |       To:       jwert ilstechnology com                                                                   
  |       cc:       xml gnome org                                                                             
  |       Subject:  Re: [xml] xmlTextReaderReadOuterXml and xmlTextReaderReadInnerXml                         

On Sun, May 22, 2005 at 06:57:54PM -0400, jwert ilstechnology com wrote:
What would it take to get the following code pushed to the head?  I'd do
myself, but I'm not sure if you have some process you want to follow:

  Humm, I initially hoped to be able to extract this directly from the
real input buffer, not a reserialized version. On the other hand it's
better to have a implemented API than an unimplemented block for 2 more
years :-)

    doc = xmlNewDoc(NULL);
    node = xmlDocCopyNode(node, doc, 1);
    buff = xmlBufferCreate();

  I don't understand why you copy the subtree in both call. First
it's inefficient, second you loose some of the characteristics of the
initial document like the encoding.

    resbuf = xmlMalloc(buff->size + 1);
    memcpy(resbuf, buff->content, buff->size);
    resbuf[buff->size] = '\0';

  I think it's better to return buff->content directly, one just need to
replace it by NULL in the structure before calling xmlBufferFree(buff);

  I also could not spot the difference in your code between
xmlTextReaderReadInnerXml and xmlTextReaderReadOuterXml, might be an
oversight from me but they really should not have the same behaviour,
could you explain ?

  So in the current state, I don't think this can be applied to the current
code, those 3 issues need to be resolved first but it should not be hard.



Daniel Veillard      | Red Hat Desktop team
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]