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

Re: [xml] get contents literally (or strip outer element tags)?



2008/3/2, Hans Martin <HMartin1 gmx net>:
> Hi,
>
>  I'm using libxml2 2.6.31 with Python 2.4. I try to get from:
>
>   <a>some <b>content</b> is &in; here</a>
>
>  the content of "a" unchanged:
>
>   some <b>content</b> is &in; here
>
>  However, with the get_contents and children methods, I don't get
>  that literally. Is there a method for that? If not, does libxml2
>  provide for a convenient method to strip the "a" element tags?

For this, I think you need to traverse the children of <a> and dump
them individually. E.g:

/* Dump the children of node */
int print_contents(xmlDoc *doc, xmlNode* node)
{
    xmlBufferPtr buf;
    xmlNode* cur;

    for (cur = node->children; cur; cur = cur->next) {
        buf = xmlBufferCreate();
        if (!xmlNodeDump(buf, doc, cur, 0, 0)) {
            fprintf(stderr, "could not dump node\n");
            xmlBufferFree(buf);
            return(1);
        }
        printf(xmlBufferContent(buf));
        xmlBufferFree(buf);
    }
    return(0);
}

Regards,
Aron


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