[Anet-checkins] CVS: ANet/ANet_Daemon/Linux XMLParser.c,NONE,1.1 test.xml,NONE,1.1 Makefile.in,1.2,1
Status: Abandoned
Brought to you by:
benad
From: Benoit N. <be...@us...> - 2002-01-02 21:48:39
|
Update of /cvsroot/anet/ANet/ANet_Daemon/Linux In directory usw-pr-cvs1:/tmp/cvs-serv20035/ANet/ANet_Daemon/Linux Modified Files: Makefile.in main.c Added Files: XMLParser.c test.xml Log Message: Starting XML parser. --- NEW FILE: XMLParser.c --- #define DEFINE_XML_HASH #include "XMLParser.h" #include <gnome-xml/xmlmemory.h> #include <gnome-xml/parser.h> #include <stdlib.h> #include <string.h> ANetMemoryTag XMLHash; // TODO: Use MemoryTags everywhere // OR something like "XMLHashFlatten/Expand"... typedef struct { struct ANetTagIDListItem *next; struct ANetTagIDListItem *prev; ANetTagID id; ANetTag tag; } ANetTagIDListItem; typedef struct { struct ANetAttributeIDListItem *next; struct ANetAttributeIDListItem *prev; ANetAttributeID id; ANetAttribute attribute; } ANetAttributeIDListItem; typedef struct { ANetTagIDListItem *tags; ANetAttributeIDListItem *attributes; } ANetXMLHash; UInt32 ANetInitXMLParser() { XMLHash = NewMemoryBlock(sizeof(ANetXMLHash), 0); xmlKeepBlanksDefault(0); return 0; } UInt32 ANetCleanupXMLParser() { DeleteMemoryBlock(XMLHash); return 0; } UInt32 ANetParseXMLFile(char *file, ANetTagID *tag) { ANetXMLHash *hash; ANetTagIDListItem *curTag; xmlDocPtr doc; xmlNodePtr curNode; //char *name; if (!(doc = xmlParseFile(file))) return -1; if (!(curNode = xmlDocGetRootElement(doc))) { xmlFreeDoc(doc); return -1; } ResolveMemoryTag(XMLHash, (UInt8**)(&hash)); curTag = (ANetTagIDListItem*)(malloc(sizeof(ANetTagIDListItem))); curTag->tag.name = malloc(strlen(curNode->name)+1); strcpy(curTag->tag.name, curNode->name); curTag->next = NULL; curTag->tag.parent = NULL; curTag->tag.children = NULL; curTag->tag.attributes = NULL; curTag->id = 0; hash->tags = curTag; *tag = (ANetTagID)0; xmlFreeDoc(doc); xmlCleanupParser(); return 0; } UInt32 ANetGetTagName(ANetTagID tagID, UInt8 *nameBuffer, UInt16 maxNameSize) { ANetXMLHash *hash; ANetTagIDListItem *cur; ANetTag *tag; ResolveMemoryTag(XMLHash, (UInt8**)(&hash)); for (cur = hash->tags; cur; cur = (ANetTagIDListItem*)(cur->next)) { if (cur->id == tagID) break; } if (!cur) return -1; tag = &(cur->tag); if (strlen(tag->name)+1 >= maxNameSize) return -1; strcpy(nameBuffer, tag->name); return -1; } --- NEW FILE: test.xml --- <?xml version="1.0"?> <test> <child1/> <child2/> </test> Index: Makefile.in =================================================================== RCS file: /cvsroot/anet/ANet/ANet_Daemon/Linux/Makefile.in,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.in 2001/11/17 00:06:25 1.2 --- Makefile.in 2002/01/02 21:48:37 1.3 *************** *** 2,6 **** # Add paths to all the headers here. ! header_paths = -I. -I../Common -I../Core -I../Common/Lists # Change compiler options here --- 2,6 ---- # Add paths to all the headers here. ! header_paths = -I. -I../Common -I../Core -I../Common/Lists -I/usr/include # Change compiler options here *************** *** 8,12 **** # Change linker options here ! linker = gcc -lm # Add source and header files paths here --- 8,12 ---- # Change linker options here ! linker = gcc -lm -lxml # Add source and header files paths here Index: main.c =================================================================== RCS file: /cvsroot/anet/ANet/ANet_Daemon/Linux/main.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.c 2001/12/01 01:48:09 1.4 --- main.c 2002/01/02 21:48:37 1.5 *************** *** 3,9 **** --- 3,11 ---- #include "Modules.h" #include "Args.h" + #include "XMLParser.h" void MemoryTest(); void ArgsTest(); + void ParserTest(); int main(int argc, char **argv) *************** *** 13,17 **** //Do some stuff here... //MemoryTest(); ! ArgsTest(); printf("Closing ANet daemon...\n"); --- 15,20 ---- //Do some stuff here... //MemoryTest(); ! //ArgsTest(); ! ParserTest(); printf("Closing ANet daemon...\n"); *************** *** 42,44 **** --- 45,61 ---- printf("%d\n", GetArgument(args, "hello-w", val, 40)); printf("%s\n", val); + } + + void ParserTest() + { + ANetTagID root; + char name[60]; + + ANetInitXMLParser(); + ANetParseXMLFile("test.xml", &root); + + ANetGetTagName(root, name, 60); + printf("Root tag's name is: \'%s\'\n", name); + + ANetCleanupXMLParser(); } |