Source Code File 04-03_xmlfile
04-03_xmlfile.c
#include <stdio.h>
#include <stdlib.h>
#include <libxml/parser.h>
int main()
{
const char filename[] = "sample.xml";
xmlDocPtr doc;
xmlNodePtr root;
doc = xmlParseFile(filename);
if( doc==NULL )
{
fprintf(stderr,"Unable to process %s\n",filename);
exit(1);
}
root = xmlDocGetRootElement(doc);
printf("Root node is '%s'\n",root->name);
xmlFreeDoc(doc);
return(0);
}
Output
Root node is 'character'
Notes
* Always test the return value of xmlParseFile().
Copyright © 1997-2025 by QPBC.
All rights reserved
