示例#1
0
STATIC void EXPAT_EndElement(void * ctx, XML_Str tag)
{
    ExpatContext * expat = (ExpatContext *)ctx;
    if (expat->cb.endElem) {
        EXPAT_ConvertTag(&expat->sb, tag);
        (*expat->cb.endElem)(expat->ctx, STRBUF_Text(&expat->sb));
    }
}
示例#2
0
文件: s_xmlp.c 项目: danying/v2uros
STATIC void EXPAT_StartElement(void * ctx, XML_Str tag, XML_Str * atts)
{
    ExpatContext * expat = (ExpatContext *)ctx;
    if (expat->cb.startElem) {
        XMLAttr aset;
        XML_Str * s = atts;

        BUFFER_Clear(&expat->buf);
        BUFFER_Clear(&expat->atts);
        while (*s) {
            wchar_t* ws;
            XML_Str xs = *s++;

            /* 
             * store offset in the vector - later will be replaces with the 
             * pointer. Cannot store the pointers now because buffer may be
             * reallocated during conversion. 
             */
            const int off = BUFFER_Size(&expat->buf)/sizeof(Char);
            BUFFER_Put(&expat->atts, &off, sizeof(off), False);

            /* Convert from UTF-8 XML_Str to Str */
            ws = STRING_ToUnicode(xs);
            if (ws) {
#ifdef UNICODE
                BUFFER_Put(&expat->buf,ws,(wcslen(ws)+1)*sizeof(ws[0]),False);
#else
                char * mb = STRING_ToMultiByte(ws);
                if (mb) {
                    BUFFER_Put(&expat->buf, mb, strlen(mb)+1, False);
                    MEM_Free(mb);
                } else {
                    BUFFER_Put(&expat->buf, xs, strlen(xs)+1, False);
                }
#endif
                MEM_Free(ws);
            }
        }

        ASSERT(!((BUFFER_Size(&expat->atts)/sizeof(int))%2));
        aset.storage = BUFFER_Access(&expat->buf);
        aset.size = BUFFER_Size(&expat->buf);
        aset.off = BUFFER_Access(&expat->atts);
        aset.n = BUFFER_Size(&expat->atts)/sizeof(int)/2;

        EXPAT_ConvertTag(&expat->sb, tag);
        (*expat->cb.startElem)(expat->ctx, STRBUF_Text(&expat->sb), &aset);
    }
}
示例#3
0
STATIC void EXPAT_StartElement(void * ctx, XML_Str tag, XML_Str * atts)
{
    ExpatContext * expat = (ExpatContext *)ctx;
    if (expat->cb.startElem) {
        XMLAttr aset;
        XML_Str * s = atts;

        BUFFER_Clear(&expat->buf);
        VECTOR_Clear(&expat->atts);
        while (*s) {
            Char tmp;
            const XML_Char * c = (*s);

            /* 
             * store offset in the vector - later will be replaces with the 
             * pointer. Cannot store the pointers now because buffer may be
             * reallocated during conversion. 
             */
            int off = BUFFER_Size(&expat->buf)/sizeof(Char);
            VECTOR_Add(&expat->atts,(VElement)(PtrWord)off);
            
            /*
             * Pretty naive convertion of attribute names and values from
             * XML_Str to Str. This part may need some improvement...
             */
            while (*c) {
                tmp = (Char)*c;
                BUFFER_Put(&expat->buf, &tmp, sizeof(tmp), False);
                c++;
            }
            tmp = 0;
            BUFFER_Put(&expat->buf, &tmp, sizeof(tmp), False);
            s++;
        }

        ASSERT(!(VECTOR_Size(&expat->atts)%2));
        aset.storage = (Char*)BUFFER_Access(&expat->buf);
        aset.size = BUFFER_Size(&expat->buf);
        aset.off = (int*)VECTOR_GetElements(&expat->atts);
        aset.n = VECTOR_Size(&expat->atts)/2;

        EXPAT_ConvertTag(&expat->sb, tag);
        (*expat->cb.startElem)(expat->ctx, STRBUF_Text(&expat->sb), &aset);
    }
}