[xml] problem about using libxml2 on windows
- From: Kun Niu <haoniukun gmail com>
- To: xml gnome org
- Subject: [xml] problem about using libxml2 on windows
- Date: Wed, 3 Aug 2005 14:26:09 +0800
Dear all,
I've got a sample xml file as follows:
<SKIN>
<ELEMENT>
<TYPE>
BUTTON
</TYPE>
<LEFT>
0
</LEFT>
<TOP>
0
</TOP>
<WIDTH>
1
</WIDTH>
<HEIGHT>
1
</HEIGHT>
<CONTENT-TYPE>
PIC
</CONTENT-TYPE>
<CONTENT>
1
</CONTENT>
</ELEMENT>
<ELEMENT>
<TYPE>
BUTTON
</TYPE>
<LEFT>
1
</LEFT>
<TOP>
0
</TOP>
<WIDTH>
2
</WIDTH>
<HEIGHT>
2
</HEIGHT>
<CONTENT-TYPE>
PIC
</CONTENT-TYPE>
<CONTENT>
33242324
</CONTENT>
</ELEMENT>
</SKIN>
And I wrote the following program to parse it:
/*********************************
xmltest.c
*********************************/
#define LIBXML_TREE_ENABLED
#include<libxml2/win32config.h>
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#ifdef LIBXML_TREE_ENABLED
static void
print_element_names( xmlDoc *doc, xmlNode * a_node)
{
xmlNode *cur_node = NULL;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
printf( "content:%s\n", xmlNodeListGetString( doc, cur_node, 1 ) );
}
print_element_names( doc, cur_node->children);
}
}
int
main(int argc, char **argv)
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
if (argc != 2)
return(1);
LIBXML_TEST_VERSION
/*parse the file and get the DOM */
doc = xmlParseFile(argv[1]);
if (doc == NULL) {
printf("error: could not parse file %s\n", argv[1]);
}
/*Get the root element node */
root_element = xmlDocGetRootElement(doc);
print_element_names( doc, root_element);
/*free the document */
xmlFreeDoc(doc);
/*
*Free the global variables that may
*have been allocated by the parser.
*/
xmlCleanupParser();
return 0;
}
#else
int main(void) {
fprintf(stderr, "Tree support not compiled in\n");
exit(1);
}
#endif
If I try to print the name of the element, I got the right result.
But if I wrote program like this I can only get some blank lines.
Would someone be kind enough to tell me how to get the content of the node?
Any help would be appreciated.
Thanks in advance:)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]