hermet pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=ca0e51a2c649a7b21303d5fd48bad2f9e08cbb7c

commit ca0e51a2c649a7b21303d5fd48bad2f9e08cbb7c
Author: ChunEon Park <chuneon.p...@samsung.com>
Date:   Thu Jun 18 19:50:00 2015 +0900

    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.
---
 src/examples/eina/eina_simple_xml_parser_02.c | 73 +++++++++++++++++++++++++++
 src/examples/eina/exia.xml                    |  5 ++
 2 files changed, 78 insertions(+)

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 0000000..0d8269a
--- /dev/null
+++ b/src/examples/eina/eina_simple_xml_parser_02.c
@@ -0,0 +1,73 @@
+//Compile with:
+//gcc -Wall -o eina_simple_xml_parser_02 eina_simple_xml_parser_02.c 
`pkg-config --cflags --libs eina`
+
+#include <Eina.h>
+#include <stdio.h>
+#include <string.h>
+
+
+static Eina_Bool
+_xml_attribute_parse_cb(void *data, const char *key, const char *value)
+{
+   printf("attributes, key = %s, value = %s\n", key, value);
+   return EINA_TRUE;
+}
+
+static Eina_Bool
+_xml_tag_parse_cb(void *data, Eina_Simple_XML_Type type, const char *content,
+                  unsigned offset EINA_UNUSED, unsigned int length)
+{
+   if (length <= 0) return EINA_FALSE;
+
+   if (type == EINA_SIMPLE_XML_OPEN)
+     {
+        //Print tag
+        if (!strncmp("Group", content, strlen("Group")))
+          printf("tag = Group\n");
+        else if (!strncmp("Label", content, strlen("Label")))
+          printf("tag = Label\n");
+
+        //Print attributes
+        const char *tags = eina_simple_xml_tag_attributes_find(content, 
length);
+        eina_simple_xml_attributes_parse(tags, length - (tags - content),
+                                         _xml_attribute_parse_cb, NULL);
+     }
+
+   return EINA_TRUE;
+}
+
+int
+main(void)
+{
+   FILE *file;
+   long size;
+
+   eina_init();
+
+   //1. Open XML File
+   file = fopen("exia.xml", "rb");
+
+   if (!file) return 0;
+
+   fseek(file, 0, SEEK_END);
+   size = ftell(file);
+   fseek(file, 0, SEEK_SET);
+
+   //2. Read XML File
+   char *buffer = malloc(size);
+   if (!buffer)
+     {
+        fclose(file);
+        return 0;
+     }
+
+   fread(buffer, 1, size, file);
+
+   //3. Start Parsing XML
+   eina_simple_xml_parse(buffer, size, EINA_FALSE, _xml_tag_parse_cb, NULL);
+
+   fclose(file);
+   free(buffer);
+
+   return 0;
+}
diff --git a/src/examples/eina/exia.xml b/src/examples/eina/exia.xml
new file mode 100644
index 0000000..f5ae55b
--- /dev/null
+++ b/src/examples/eina/exia.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Group xmlns="http://www.enlightenment.org/docs";>
+  <Label text="0 is bigger than3? (0 > 3 ?)">
+  </Label>
+</Group>

-- 


Reply via email to