Source Code File 04-04_xmlprolog
04-04_xmlprolog.c
#include <stdio.h> #include <stdlib.h> #include <libxml/parser.h> int main() { const char filename[] = "sample.xml"; xmlDocPtr doc; doc = xmlParseFile(filename); if( doc==NULL ) { fprintf(stderr,"Unable to process %s\n",filename); exit(1); } printf("XML version is %s\n",doc->version); printf("XML encoding is %s\n",doc->encoding); xmlFreeDoc(doc); return(0); }
Output Screenshot
XML version is 1.0
XML encoding is UTF-8
Notes
* If the prolog information isn't available, NULL pointers are returned for the version and encoding members of the xmlDocPtr structure. Ensure that you test for this possibility in your code.
Copyright © 1997-2024 by QPBC.
All rights reserved