Hi, first post here .
I'd like to parse an XML file in C. I have C/C++ experience, but have not done this for a while.
This is my code example:
Code:
#include <stdio.h>#include <libxml2/parser.h>
#include <libxml2/tree.h>
static const char * document = "<doc/>";
static void example3Func(const char * content, int length);
int main(int argc, char * argv[])
{
LIBXML_TEST_VERSION
// read our document (which is a dummy in this case).
example3Func(document, 6);
// cleanup function for the XML library.
xmlCleanupParser();
// this is to debug memory for regression tests.
xmlMemoryDump();
return 0;
}
static void example3Func(const char * content, int length)
{
xmlDocPtr doc;
doc = xmlReadMemory(content, length, "noname.xml", NULL, 0);
if (NULL == doc)
{
fprintf(stderr, "ERROR: Failed to parse document!\n\n");
return;
}
else
{
printf("SUCCESS: Document parsed succesfully!\n\n");
}
xmlFreeDoc(doc);
}
When I compile, this is what I get:
Code:
$ gcc -o parse-xml parse-xml.c
parse-xml.c:5:28: fatal error: libxml2/parser.h: No such file or directory
compilation terminated.
I'm doing this in cygwin.
When I run the whereis command, libxml seems to be installed:
Code:
$ whereis libxml
libxml: /lib/libxml2.la /usr/lib/libxml2.la /usr/share/man/man3/libxml.3.gz
What am I doing wrong?