\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_gafee4bfc0e509b6ffed6598edf6f4b3de}{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_gad671e356ded4049ccff24cc46f6f6f43}{eina\_array\_new}}(10);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Simple__XML__Group_gacbbb2b975f6f3e1d0a3d2215cc37da82}{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_gaee9eb6a413ab294a5d69771f14cf3543}{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_ga2c8b4020427108a30c44707af22c99d3}{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_gaa356517d0c834904432275d7edd2a892}{eina\_simple\_xml\_tag\_attributes\_find}}(content,}
\DoxyCodeLine{                                                                    length);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__Simple__XML__Group_ga9525b33f8d78eb23def4f660b290f794}{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_ga73466cfd3c7d64608d77706e4bc43e25}{eina\_strlcpy}}(buffer, content, \textcolor{keyword}{sizeof}(buffer));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga3172a47b021bb56263a591e2fefdc729}{eina\_strlcat}}(str, \textcolor{stringliteral}{"{}<"{}}, 1);}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga3172a47b021bb56263a591e2fefdc729}{eina\_strlcat}}(str, buffer, \textcolor{keyword}{sizeof}(str));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga3172a47b021bb56263a591e2fefdc729}{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_ga73466cfd3c7d64608d77706e4bc43e25}{eina\_strlcpy}}(buffer, content, \textcolor{keyword}{sizeof}(buffer));}
\DoxyCodeLine{             \mbox{\hyperlink{group__Eina__String__Group_ga3172a47b021bb56263a591e2fefdc729}{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}
 