Ir ao conteúdo
  • Cadastre-se

Entender código em C


Adriano Bisteca

Posts recomendados

Olá amigos, Alguém poderia comentar esse código ?

 

Sei que ele trabalha em cima do xml.

Queria entender linha por linha ( sua estrutura). Alguém pode me ajudar comentando o código?.

#include "SDK30.h" #include "XMLs.h"   static void __TraceDebug( const char* pString, ... )   {        char String[512];        int nLength;        va_list Params;        va_start(Params, pString);   #ifdef __GNUC__        nLength = vsprintf(String, pString, &Params);   #else        nLength = vsprintf(String, pString, Params);   #endif        va_end(Params);        trace(SAP_DEBUG_TRACE, nLength, String);   }   static void __XmlStartElement( XMLs_PARSER hXml, const char* szName, XMLs_ATTRIBUTE_HANDLE hAttribute )   {        int nIndex;        int nAttributes = XMLs_Attributes_GetCount( hAttribute );        const char* szAttributeName;        const char* szAttributeValue;        int* pStartTags;        __TraceDebug( "Start of Tag [%s]", szName );        // Retrieve and modify the parsing context.        pStartTags   = (int*)XMLs_GetUserData( hXml );        *pStartTags += 1;        // List all the attributes...        for( nIndex = 0; nIndex < nAttributes; nIndex++ )        {                XMLs_Attributes_GetByIndex( hAttribute, nIndex, &szAttributeName, &szAttributeValue );                __TraceDebug( "Attribute [%s] = [%s]", szAttributeName, szAttributeValue );        }        // ...or look for a specific one.        szAttributeValue = XMLs_Attributes_GetByName( hAttribute, "color", 0 );        if( szAttributeValue != NULL )        {                __TraceDebug( "Attribute [color] found ! [%s]", szAttributeValue );        }   }   static void __XmlEndElement( XMLs_PARSER hXml, const char* szName )   {        __TraceDebug( "End of Tag [%s]", szName );   }   static void __XmlData( XMLs_PARSER hXml, const char* pcDataBuffer, unsigned int nDataLength )   {        char* szData = XMLs_ProcessData( pcDataBuffer, nDataLength, XML_DATA_ALL );        if( szData != NULL )        {                __TraceDebug( "Xml Data [%s]", szData );                ufree( szData );        }   }   static const char* XML_SAMPLE_BUFFER =        "<?xml version=\"1.0\" ?>"        "<garage>"        "    <car name=\"104\">"        "        Tributes to JRP"        "        <feature manufacturer=\"Peugeot\" logo=\"lion\"/>"        "        <feature color=\"white\"/>"        "        <feature price=\"1250$\"/>"        "    </car>"        "    <car name=\"R9\">"        "        <feature manufacturer=\"Renault\" logo=\"lozenge\"/>"        "        <feature color=\"blue\"/>"        "        <feature year=\"1982\" model=\"1983\"/>"        "        <feature engine=\"1.8L\">"        "            <engine top_speed=\"45mph\"/>"        "            <engine gear=\"4\"/>"        "        </feature>"        "    </car>"        "</garage>";   void Xmls_Sample( void )   {        XMLs_PARSER hXml;        int nStartTags = 0;        int nReturn;        hXml = XMLs_Create();        if( hXml != NULL )        {                // Set the parsing callbacks.                XMLs_SetOption( hXml, XMLs_START_ELEMENT_HANDLER, __XmlStartElement );                XMLs_SetOption( hXml, XMLs_END_ELEMENT_HANDLER, __XmlEndElement );                XMLs_SetOption( hXml, XMLs_DATA_HANDLER, __XmlData );                // Set the parsing context.                XMLs_SetUserData( hXml, &nStartTags );                // Launch the parser.                nReturn = XMLs_ParseBuffer( hXml, XML_SAMPLE_BUFFER, strlen(XML_SAMPLE_BUFFER) );                // nReturn = XMLs_ParseFile( hXml, "/HOST/SAMPLE.XML" );                if( nReturn == XMLS_OK )                {                        __TraceDebug( "XML parsing successful - [%d] tags found !", nStartTags );                }                XMLs_Destroy( hXml );        }   }
Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...