Skip to content
Snippets Groups Projects
Commit c13fdc46 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

updated files

parent 8c472f1c
No related branches found
No related tags found
No related merge requests found
main.c 0 → 100644
#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "xml_parser.h"
int main() {
char filename[] = "villes.xml";
read_xml(filename);
return EXIT_SUCCESS;
}
\ No newline at end of file
...@@ -44,3 +44,47 @@ void graph_xml_parser(xmlNode * a_node) ...@@ -44,3 +44,47 @@ void graph_xml_parser(xmlNode * a_node)
} }
} }
int read_xml(const char * filename) {
// Init libxml
xmlInitParser();
LIBXML_TEST_VERSION
// create a parser context
xmlParserCtxtPtr ctxt;
xmlDocPtr doc = NULL;
ctxt = xmlNewParserCtxt();
if (ctxt == NULL) {
fprintf(stderr, "Failed to allocate parser context\n");
return EXIT_FAILURE;
}
// parse the file, without error validation
doc = xmlCtxtReadFile(ctxt, filename, NULL, XML_PARSE_NOERROR);
// check if parsing suceeded
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
} else {
/* check if validation suceeded */
if (ctxt->valid == 0)
fprintf(stderr, "Failed to validate %s\n", filename);
}
xmlNode *root_element = xmlDocGetRootElement(doc);
// get cities from xml
city_xml_parser(root_element);
// get graph from xml
graph_xml_parser(root_element);
// free the document
xmlFreeDoc(doc);
// free up the parser context
xmlFreeParserCtxt(ctxt);
return EXIT_SUCCESS;
}
\ No newline at end of file
...@@ -24,4 +24,6 @@ void ville_xml_parser(xmlNode * a_node); ...@@ -24,4 +24,6 @@ void ville_xml_parser(xmlNode * a_node);
*/ */
void graph_xml_parser(xmlNode * a_node); void graph_xml_parser(xmlNode * a_node);
int read_xml(const char * filename);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment