PNG IHDR ; IDATxܻn0K )(pA7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5 bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô!x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%tMז -lG6mrz2s%9s@-k9=)kB5\+͂ZsٲRn~GRCwIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL /F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ R IENDB`
Parsing the file requires only the name of the file and a single function call, plus error checking. Full code: AppendixC, Code for Keyword Example
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) { fprintf(stderr,"Document not parsed successfully. \n"); return; }
cur = xmlDocGetRootElement(doc);
if (cur == NULL) { fprintf(stderr,"empty document\n"); xmlFreeDoc(doc); return; }
if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { fprintf(stderr,"document of the wrong type, root node != story"); xmlFreeDoc(doc); return; }
![]() | Declare the pointer that will point to your parsed document. | ||||
![]() | Declare a node pointer (you'll need this in order to interact with individual nodes). | ||||
![]() | Check to see that the document was successfully parsed. If it was not, libxml will at this point register an error and stop.
| ||||
![]() | Retrieve the document's root element. | ||||
![]() | Check to make sure the document actually contains something. | ||||
![]() | In our case, we need to make sure the document is the right type. "story" is the root type of the documents used in this tutorial. |