[xml] can't get the value of the node plz advice



hi

i am using  "xmlReadFile(filename, "utf-8", XML_PARSE_DTDVALID )"  to read a xml file and then traverse the tree. This is what my aml file looks like

<document>
<name>Windows</name>
<date>Menus and Toolbars</date>
<descrip>Customize the appearance of toolbars and menubars in applications</descrip>
</document>

now when traversing the tree to get the values of the nodes in name , date , descrip i use this code

static void
print_element_names (xmlDocPtr doc,xmlNodePtr a_node, unsigned char** values , int *char_count)
{
    xmlNodePtr cur_node = a_node;
    xmlChar *nam = "name" ;
    xmlChar *dat = "date" ;
    xmlChar *des = "descrip" ;
    xmlChar *docu = "document" ;
     gint count ;    

    count = 1 ;


    do
    {
           if (cur_node->type == XML_ELEMENT_NODE)
            {
                    g_printf("\n 1 node : %s  value[1] = %s  , \n size = %d \n\n ", cur_node->name ,  xmlNodeGetContent(cur_node->children) , 0);//char_count[count]);

                     if(xmlStrcmp(cur_node->name,docu) == 0)
                    {
                            print_element_names (doc, cur_node->ch ildren , values , char_count) ;
                    }
                    else
                    {
  116:                          values[count] = xmlNodeGetContent(cur_node->children);
                            char_count[count] = xmlStrlen((xmlChar *)values[count]) ;
                            g_printf("\n2  node : %s  value[1] = %s  , \n size = %d \n\n ", cur_node->name ,  values[count] , char_count[count]);
                                count = count + 1 ;
                            }
            }
    cur_node = cur_node->next ;
    }while(cur_node != NULL) ;
                printf("\n print: after for\n");
}

the printf's are just for debugging. What actually happens is that in first recursiive call at cur_node->name = "name"
values[count] = xmlNodeGetContent(cur_node->children);
(this is line no. 116 in my file)
gives me an error

0x08049d2e in print_element_nam es (doc=0x8acd9a0, a_node=Variable "a_node" is not available.
) at interface.c:116

the code has been taken from tree example itself.

can u plz tell me what is wrong here and how can i correct it thanks.
Also is there a better way of getting the values of the node


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]