示例#1
0
文件: xmlparser.cpp 项目: Adatan/vlc
bool XMLParser::parse()
{
    const char *node;
    int type;

    if( !m_pReader ) return false;

    m_errors = false;

    while( (type = xml_ReaderNextNode( m_pReader, &node )) > 0 )
    {
        if( m_errors ) return false;

        switch( type )
        {
            case XML_READER_STARTELEM:
            {
                // Read the attributes
                AttrList_t attributes;
                const char *name, *value;
                while( (name = xml_ReaderNextAttr( m_pReader, &value )) != NULL )
                    attributes[strdup(name)] = strdup(value);

                handleBeginElement( node, attributes );

                map<const char*, const char*, ltstr> ::iterator it =
                    attributes.begin();
                while( it != attributes.end() )
                {
                    free( (char *)it->first );
                    free( (char *)it->second );
                    ++it;
                }
                break;
            }

            // End element
            case XML_READER_ENDELEM:
            {
                handleEndElement( node );
                break;
            }
        }
    }
    return (type == 0 && !m_errors );
}
示例#2
0
bool XMLParser::parse()
{
    if( !m_pReader )
    {
        return false;
    }

    m_errors = false;

    int ret = xmlTextReaderRead( m_pReader );
    while (ret == 1)
    {
        if( m_errors )
        {
            return false;
        }
        // Get the node type
        int type = xmlTextReaderNodeType( m_pReader );
        switch (type )
        {
            // Error
            case -1:
                return false;
                break;

            // Begin element
            case 1:
            {
                // Read the element name
                const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
                if( !eltName )
                {
                    return false;
                }
                // Read the attributes
                AttrList_t attributes;
                while( xmlTextReaderMoveToNextAttribute( m_pReader ) == 1 )
                {
                    const xmlChar *name = xmlTextReaderConstName( m_pReader );
                    const xmlChar *value = xmlTextReaderConstValue( m_pReader );
                    if( !name || !value )
                    {
                        return false;
                    }
                    attributes[(const char*)name] = (const char*)value;
                }
                handleBeginElement( (const char*)eltName, attributes);
                break;
            }

            // End element
            case 15:
                // Read the element name
                const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
                if( !eltName )
                {
                    return false;
                }
                handleEndElement( (const char*)eltName );
                break;
        }
        ret = xmlTextReaderRead( m_pReader );
    }
    return (ret == 0 && !m_errors );
}