From: Wang, Hai (hwang@accuris.ie)
Date: Thu Dec 07 2000 - 04:57:22 EST
Hello everybody,
I have got a problem with gnome parser, I tried to parse a XML doc
from memory, it was good, but when I tried to traverse the xml tree in
xmlDocPtr to get all the nodes and print out their names, attributesname and
contents, I find the following problems:
1. Node name is correct, but with text node, (I want to get rid of the text
node).
2. attributes are empty
3 contents are all empty.
The part of my codes are as follows:
//-----------Parse XML file from memory-----------------------
FILE* f;
char* filename = argv[1];
f=fopen(filename, "r");
int res, size = 102400;
char chars[102400];
res = fread(chars,1, 102400, f);
xmlDocPtr xml_xmlDocPtr;
const xmlChar* list[102400];
xml_xmlDocPtr = xmlParseMemory(chars, res);
if(xml_xmlDocPtr == NULL)
{
return -1;
}
//-----------------------------------end of
parsing-------------------------------------
//-----------------printing-------------------------------------------------
---------------
if(xml_xmlDocPtr != NULL)
{
node = xmlDocGetRootElement(xml_xmlDocPtr);
printsubnodename(node);
}
void printsubnodename(xmlNodePtr parentnode)
{
xmlNodePtr currentnode;
if(parentnode == NULL)
{
return;
}
currentnode = parentnode->children;
while(currentnode != NULL)
{
printf("nodename: %s\n", currentnode->name);
printf("\t node content: %s\n",
currentnode->content);
printattriname(currentnode);
currentnode = currentnode->next;
}
}
void printattriname(xmlNodePtr currentnode)
{
if(currentnode == NULL)
{
return;
}
xmlAttr* nodeattr = currentnode->properties;
while( nodeattr != NULL) // all empty ?????
{
printf("\t\t preporty name: %s\n", nodeattr->name);
nodeattr = nodeattr->next;
}
}
//--------------------------------------------------------------------------
----------------
I just wonder if there is an existing approaches to do this job, I
appreciate any hints and help.
Thank you
!
Hai Wang
---- Message from the list xml@rpmfind.net Archived at : http://xmlsoft.org/messages/ to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
This archive was generated by hypermail 2b29 : Thu Dec 07 2000 - 05:43:49 EST