Reading AtomPerson from a XML node
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 20:14:48 +0000 (17:14 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 20:14:48 +0000 (17:14 -0300)
atom/person.c
include/atompub/person-xml.h

index 62f9ed4..b60e46e 100644 (file)
@@ -106,3 +106,24 @@ atom_person_to_xmlnode (AtomPerson *person, char *elname)
     xmlNewTextChild (node, NULL, "email", person->email);
   return node;
 }
+
+AtomPerson *
+atom_person_new_from_xmlnode (xmlNodePtr node)
+{
+  xmlNodePtr child;
+  AtomPerson *person;
+  person = g_slice_new0 (AtomPerson);
+  for (child = node->xmlChildrenNode; child != NULL; child = child->next)
+    {
+      char *content = xmlNodeGetContent (child->xmlChildrenNode);
+      if (!xmlStrcmp (child->name, "name"))
+       person->name = content;
+      else if (!xmlStrcmp (child->name, "uri"))
+       person->uri = content;
+      else if (!xmlStrcmp (child->name, "email"))
+       person->email = content;
+      else
+       xmlFree (content);
+    }
+  return person;
+}
index 69b7508..7d333c0 100644 (file)
@@ -25,5 +25,6 @@
 #include <libxml/tree.h>
 
 xmlNodePtr atom_person_to_xmlnode (AtomPerson *, char *);
+AtomPerson * atom_person_new_from_xmlnode (xmlNodePtr);
 
 #endif