[Expat-discuss] SAX and children node

Patos patos.legit at gmail.com
Fri Jul 21 23:44:38 CEST 2006


There is a better exemple of what im currently doing :

void XMLStartElementHandler(void *data, const char *name, const char **atts)
{
    XmlReader *p = reinterpret_cast<XmlReader *>(data);
    XmlNode *xn = p->m_pCurrentReader->m_pCurrentNode;
    /* default value. */
    xn->m_ChildNodes = true;
    xn->m_Name = String(name);
    /* retrieve the node attribute. */
    for (int i = 0; atts[i]; i += 2)
    {
            XmlAttribute *att = new XmlAttribute(String(atts[i]),
String(atts[i + 1]));
            /* add the attribute. */
            xn->m_pAttrList->Add(att);
     }
    /* node readed. */
    p->m_pCurrentReader->m_NodeComplete = true;
    xn->m_Depth = ++p->m_Depth;
}

void XMLEndElementHandler(void *data, const char *name)
{
    XmlReader *p = reinterpret_cast<XmlReader *>(data);
    XmlNodeReader *xnr = p->m_pCurrentReader;
    /* do we have child. */
    xnr->m_pCurrentNode->m_ChildNodes = p->m_Depth !=
xnr->m_pCurrentNode->m_Depth;
    p->m_Depth--; /* were done, get back to the previous depth. */
    /* stop the parser. */
    xnr->m_NodeComplete = true;
}

and im calling XML_Parse in a ReadNext method with only 4 bytes at a time
looping on the value m_NodeComplete.

Patrick


More information about the Expat-discuss mailing list