\hypertarget{eina_simple_xml_parser_01_8c-example}{}\doxysection{eina\+\_\+simple\+\_\+xml\+\_\+parser\+\_\+01.\+c}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc -\/Wall -\/o eina\_simple\_xml\_parser\_01 eina\_simple\_xml\_parser\_01.c `pkg-\/config -\/-\/cflags -\/-\/libs eina`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <string.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} \_xml\_attr\_cb(\textcolor{keywordtype}{void} *data, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *key, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *value);}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} \_xml\_tag\_cb(\textcolor{keywordtype}{void} *data, Eina\_Simple\_XML\_Type type,}
\DoxyCodeLine{                \textcolor{keyword}{const} \textcolor{keywordtype}{char} *content, \textcolor{keywordtype}{unsigned} offset, \textcolor{keywordtype}{unsigned} length);}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} \_print(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *container, \textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{void} *fdata);}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} tag\_login   = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} tag\_message = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   FILE *file;}
\DoxyCodeLine{   \textcolor{keywordtype}{long} size;}
\DoxyCodeLine{   \textcolor{keywordtype}{char} *buffer;}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Eina__Array}{Eina\_Array}} *array;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} ((file = fopen(\textcolor{stringliteral}{"{}chat.xml"{}}, \textcolor{stringliteral}{"{}rb"{}})))}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        fseek(file, 0, SEEK\_END);}
\DoxyCodeLine{        size = ftell(file);}
\DoxyCodeLine{        fseek(file, 0, SEEK\_SET);}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (size < 0)}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Log__Group_ga2e33caeeeb6051526c01b7fea4d6c91b}{EINA\_LOG\_ERR}}(\textcolor{stringliteral}{"{}Can't read chat.xml"{}});}
\DoxyCodeLine{             \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{          \}}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{keywordflow}{if} ((buffer = malloc(size)))}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \textcolor{keywordflow}{if} (fread(buffer, 1, size, file) != (\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long})size)}
\DoxyCodeLine{               \{}
\DoxyCodeLine{                  \mbox{\hyperlink{group__Eina__Log__Group_ga2e33caeeeb6051526c01b7fea4d6c91b}{EINA\_LOG\_ERR}}(\textcolor{stringliteral}{"{}Can't read chat.xml"{}});}
\DoxyCodeLine{               \}}
\DoxyCodeLine{}
\DoxyCodeLine{             array = \mbox{\hyperlink{group__Eina__Array__Group_gaf4b5844225b5359a617744210a5ed6ff}{eina\_array\_new}}(10);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Simple__XML__Group_ga2a0393367425ea29ef27d27796567380}{eina\_simple\_xml\_parse}}(buffer, size, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}},}
\DoxyCodeLine{                                   \_xml\_tag\_cb, array);}
\DoxyCodeLine{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Array__Group_ga8de2d191a0fffceb5bdc6376540b8db1}{eina\_array\_foreach}}(array, \_print, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Array__Group_ga7fa7e2cdcfb739140d5c5a5044086ce1}{eina\_array\_free}}(array);}
\DoxyCodeLine{             free(buffer);}
\DoxyCodeLine{          \}}
\DoxyCodeLine{        \textcolor{keywordflow}{else}}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Log__Group_ga2e33caeeeb6051526c01b7fea4d6c91b}{EINA\_LOG\_ERR}}(\textcolor{stringliteral}{"{}Can't allocate memory!"{}});}
\DoxyCodeLine{          \}}
\DoxyCodeLine{        fclose(file);}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{else}}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Eina__Log__Group_ga2e33caeeeb6051526c01b7fea4d6c91b}{EINA\_LOG\_ERR}}(\textcolor{stringliteral}{"{}Can't open chat.xml!"{}});}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_xml\_tag\_cb(\textcolor{keywordtype}{void} *data, Eina\_Simple\_XML\_Type type, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *content,}
\DoxyCodeLine{            \textcolor{keywordtype}{unsigned} offset \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{unsigned} length)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{char} buffer[length+1];}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Eina__Array}{Eina\_Array}} *array = data;}
\DoxyCodeLine{   \textcolor{keywordtype}{char} str[512] = \{\textcolor{charliteral}{'\(\backslash\)0'}\};}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (type == \mbox{\hyperlink{group__Eina__Simple__XML__Group_ggad43c24562b801f797d8f7cb8b3fe2d4ca5be26ebfdfdefbc411adde618c4c2dd4}{EINA\_SIMPLE\_XML\_OPEN}})}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{keywordflow}{if}(!strncmp(\textcolor{stringliteral}{"{}post"{}}, content, strlen(\textcolor{stringliteral}{"{}post"{}})))}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \textcolor{keyword}{const} \textcolor{keywordtype}{char} *tags = \mbox{\hyperlink{group__Eina__Simple__XML__Group_ga3af39eab6fc32f7ccd9278d2c7b7314a}{eina\_simple\_xml\_tag\_attributes\_find}}(content,}
\DoxyCodeLine{                                                                    length);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Simple__XML__Group_ga59ca63d8488d4af119983d6024b6da2b}{eina\_simple\_xml\_attributes\_parse}}(tags, length -\/ (tags -\/ content),}
\DoxyCodeLine{                                              \_xml\_attr\_cb, str);}
\DoxyCodeLine{          \}}
\DoxyCodeLine{        \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strncmp(\textcolor{stringliteral}{"{}login>"{}}, content, strlen(\textcolor{stringliteral}{"{}login>"{}})))}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             tag\_login = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{          \}}
\DoxyCodeLine{        \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strncmp(\textcolor{stringliteral}{"{}message>"{}}, content, strlen(\textcolor{stringliteral}{"{}message>"{}})))}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             tag\_message = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{          \}}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (type == \mbox{\hyperlink{group__Eina__Simple__XML__Group_ggad43c24562b801f797d8f7cb8b3fe2d4caea1f4a70cdfcfba5c19ce1abe363c688}{EINA\_SIMPLE\_XML\_DATA}})}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (tag\_login == \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}})}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_gae28caa0c42c4e76ae584f22bd3615723}{eina\_strlcpy}}(buffer, content, \textcolor{keyword}{sizeof}(buffer));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga9d340cfcfd1259f3ef76d314a974b0e0}{eina\_strlcat}}(str, \textcolor{stringliteral}{"{}<"{}}, 1);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga9d340cfcfd1259f3ef76d314a974b0e0}{eina\_strlcat}}(str, buffer, \textcolor{keyword}{sizeof}(str));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga9d340cfcfd1259f3ef76d314a974b0e0}{eina\_strlcat}}(str, \textcolor{stringliteral}{"{}> "{}}, 2);}
\DoxyCodeLine{             tag\_login = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{          \}}
\DoxyCodeLine{        \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (tag\_message == \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}})}
\DoxyCodeLine{          \{}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_gae28caa0c42c4e76ae584f22bd3615723}{eina\_strlcpy}}(buffer, content, \textcolor{keyword}{sizeof}(buffer));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga9d340cfcfd1259f3ef76d314a974b0e0}{eina\_strlcat}}(str, buffer, \textcolor{keyword}{sizeof}(str));}
\DoxyCodeLine{             tag\_message = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Array__Group_ga97ac1fe353f4cd7a9762af4d4db7b9c4}{eina\_array\_push}}(array, strdup(str));}
\DoxyCodeLine{          \}}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_xml\_attr\_cb(\textcolor{keywordtype}{void} *data, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *key, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *value)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{char} *str = data;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if}(!strcmp(\textcolor{stringliteral}{"{}id"{}}, key))}
\DoxyCodeLine{   \{}
\DoxyCodeLine{      snprintf(str, \textcolor{keyword}{sizeof}(value) + 3, \textcolor{stringliteral}{"{}(\%s) "{}}, value);}
\DoxyCodeLine{   \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_print(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *container \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{void} *fdata \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}}, (\textcolor{keywordtype}{char} *)data);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 