OK, i've been going round in circles with this one. I'm trying to parse an XML file / data into some structs.
Because every child element requires certain business logic to be carried out, I have decided to create separate procedures to manage each child element.
The original xml can be found here: http://hearme.fm/ars.xml
I can manage the DAAST element, this then feeds through to the Ad element, but when I try to get into the Inline element. node->name returns: "Text" and I can't seem to get any further than this.
Can anyone shed any light?
Thanks
#ifndef DAASTXML_C_ #define DAASTXML_C_ #define XMLSTR(str) ((xmlChar *)(str)) #include "daastXML.h" #include <libxml/xmlmemory.h> #include <libxml/parser.h> #include <stdio.h> #include <stdlib.h> void parseAds(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile); void parseInline(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile); void parseCreatives(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile); void daastParser (char *filePath){ xmlDocPtr doc; xmlNodePtr node; doc = xmlParseFile(filePath); node = xmlDocGetRootElement(doc); struct daastXML xmlFile; if (xmlStrcmp (node->name, XMLSTR("DAAST")) == 0){ xmlFile.version = (char *)xmlGetProp(node, XMLSTR("version")); parseAds(doc, node->children, xmlFile); } xmlFreeDoc(doc); } void parseAds(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile){ vectorAds_init(&xmlFile.Ads); do { if (node == NULL) break; if (xmlIsBlankNode(node)) continue; if (xmlStrcmp (node->name, XMLSTR("Ad")) == 0) { struct daastAd newAd; newAd.id = (char *)xmlGetProp(node, XMLSTR("id")); newAd.sequence = (char *)xmlGetProp(node, XMLSTR("sequence")); // At this point we need to get the inline (or wrapper) info *** WRAPPER NOT INTEGRATED *** printf("\nAdvert "); printf("\n"); parseInline (doc, node->children, xmlFile); vectorAds_append(&xmlFile.Ads, newAd); } } while ((node = node->next)); } void parseInline (xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile){ printf("\nInline : node name: "); printf(node->name); if (xmlStrcmp (node->name, XMLSTR("InLine")) == 0){ printf("We've got the inline element"); } parseCreatives (doc, node->children, xmlFile); } void parseCreatives(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile){ printf("\nCreatives \n"); }
No comments:
Post a Comment