[xml] xmlReaderReadOuterXml() and xmlReaderReadInnerXml()
- From: jwert ilstechnology com
- To: xml gnome org
- Subject: [xml] xmlReaderReadOuterXml() and xmlReaderReadInnerXml()
- Date: Mon, 30 May 2005 16:13:21 -0400
Hello list,
Here are functional implimentations for xmlReaderReadOuterXml() and
xmlReaderReadInnerXml().
I have tested both and they work, the "inner" version seems to be
overcomplicated, but I don't know the APIs well enough to know what else to
do. I'm also sure there is some better error checking that I can do, but
again, I'm not familiar with the API to know what I should throw for
errors.
If there are suggestions on how it can be improved, I'll work on it as I
have time, but as Daniel said, some implimentation is better than none. =]
Here is the code:
-----------------------------------
xmlChar *
xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
xmlChar *resbuf;
xmlNodePtr node,cur_node;
xmlBufferPtr buff, buff2;
xmlDocPtr doc;
xmlTextReaderExpand(reader);
doc = reader->doc;
buff = xmlBufferCreate();
for(cur_node=reader->node->children;cur_node!=NULL;cur_node=cur_node->next)
{
node = xmlDocCopyNode(cur_node, doc, 1);
buff2 = xmlBufferCreate();
xmlNodeDump(buff2, doc, node, 0, 0);
xmlBufferCat( buff, buff2->content);
xmlFreeNode(node);
xmlBufferFree(buff2);
}
resbuf = buff->content;
return resbuf;
}
xmlChar *
xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) {
xmlChar *resbuf;
xmlNodePtr node;
xmlBufferPtr buff;
xmlDocPtr doc;
node = reader->node;
doc = reader->doc;
xmlTextReaderExpand(reader);
node = xmlDocCopyNode(node, doc, 1);
buff = xmlBufferCreate();
xmlNodeDump(buff, doc, node, 0, 0);
resbuf = buff->content;
buff->content = NULL;
xmlFreeNode(node);
xmlBufferFree(buff);
return resbuf;
}
-----------------------------------
James Wert Jr.
JWert ILSTechnology com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]