summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorChunEon Park <chuneon.park@samsung.com>2015-06-18 19:50:00 +0900
committerChunEon Park <chuneon.park@samsung.com>2015-06-18 19:50:00 +0900
commitca0e51a2c649a7b21303d5fd48bad2f9e08cbb7c (patch)
tree46ee6fec65bc720c60c85ab4aeae318ebab3e34f /src/examples
parent2d31628d85f72f7187e5d262a33f7986273e1831 (diff)
eina: add eina_simple_xml example.
This example just prints tag and it's attributes in xml file. But this example intended for the scenario, if the attributes have the "<" or" >" characters inside of the string.
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/eina/eina_simple_xml_parser_02.c73
-rw-r--r--src/examples/eina/exia.xml5
2 files changed, 78 insertions, 0 deletions
diff --git a/src/examples/eina/eina_simple_xml_parser_02.c b/src/examples/eina/eina_simple_xml_parser_02.c
new file mode 100644
index 0000000000..0d8269a8fd
--- /dev/null
+++ b/src/examples/eina/eina_simple_xml_parser_02.c
@@ -0,0 +1,73 @@
1//Compile with:
2//gcc -Wall -o eina_simple_xml_parser_02 eina_simple_xml_parser_02.c `pkg-config --cflags --libs eina`
3
4#include <Eina.h>
5#include <stdio.h>
6#include <string.h>
7
8
9static Eina_Bool
10_xml_attribute_parse_cb(void *data, const char *key, const char *value)
11{
12 printf("attributes, key = %s, value = %s\n", key, value);
13 return EINA_TRUE;
14}
15
16static Eina_Bool
17_xml_tag_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content,
18 unsigned offset EINA_UNUSED, unsigned int length)
19{
20 if (length <= 0) return EINA_FALSE;
21
22 if (type == EINA_SIMPLE_XML_OPEN)
23 {
24 //Print tag
25 if (!strncmp("Group", content, strlen("Group")))
26 printf("tag = Group\n");
27 else if (!strncmp("Label", content, strlen("Label")))
28 printf("tag = Label\n");
29
30 //Print attributes
31 const char *tags = eina_simple_xml_tag_attributes_find(content, length);
32 eina_simple_xml_attributes_parse(tags, length - (tags - content),
33 _xml_attribute_parse_cb, NULL);
34 }
35
36 return EINA_TRUE;
37}
38
39int
40main(void)
41{
42 FILE *file;
43 long size;
44
45 eina_init();
46
47 //1. Open XML File
48 file = fopen("exia.xml", "rb");
49
50 if (!file) return 0;
51
52 fseek(file, 0, SEEK_END);
53 size = ftell(file);
54 fseek(file, 0, SEEK_SET);
55
56 //2. Read XML File
57 char *buffer = malloc(size);
58 if (!buffer)
59 {
60 fclose(file);
61 return 0;
62 }
63
64 fread(buffer, 1, size, file);
65
66 //3. Start Parsing XML
67 eina_simple_xml_parse(buffer, size, EINA_FALSE, _xml_tag_parse_cb, NULL);
68
69 fclose(file);
70 free(buffer);
71
72 return 0;
73}
diff --git a/src/examples/eina/exia.xml b/src/examples/eina/exia.xml
new file mode 100644
index 0000000000..f5ae55bdc0
--- /dev/null
+++ b/src/examples/eina/exia.xml
@@ -0,0 +1,5 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<Group xmlns="http://www.enlightenment.org/docs">
3 <Label text="0 is bigger than3? (0 > 3 ?)">
4 </Label>
5</Group>