[Glade-users] reading from an xml file into text entry boxes
- From: atmadarshini_dd at yahoo.com (Atmadarshini devi dasi)
- Subject: [Glade-users] reading from an xml file into text entry boxes
- Date: Fri, 15 Feb 2008 03:53:01 -0800 (PST)
Hi guys
I am having a problem. I am a new learner trying to program using C and create my user interface using glade.
I have lets say a window with 2 text entry boxes for now. I have an xml file and I want to read the entries
from the xml file and place them into the text entry box. How do i go about doing this? I am able to read
from the xml file and place the entried on the console window but when i try to read them into the text entry
box, i get an error. I am not sure how to assign the values from my xml file to the text entry boxes. Am
pasting my code below.
XML file
<addressbook>
<lastname>Dasi</lastname>
<firstname>Atma</firstname>
</addressbook>
so when i click a button, i want to see for instance Dasi in the first textbox and Atma in the second text
box. I have named my first text box as lname_entry and second textbox as fname_entry.
my code is as follows:
# include "includes.h"
#include "addressbook.h"
AddressBook *address; //AddressBook is a structure
GtkWidget *address_window; //address_window is the window with the textboxes
void addressbook_set_addresses_dialog()
{
lname_entry_widget = lookup_widget(GTK_WIDGET(address_window), "lname_entry");
GtkWidget *fname_entry_widget = lookup_widget(GTK_WIDGET(address_window), "fname_entry");
gtk_entry_set_text(GTK_ENTRY(lname_entry_widget), address->lastname);
gtk_entry_set_text(GTK_ENTRY(fname_entry_widget), address->firstname);
}
int addressbook_get_addresses_from_xml_file(char *filename)
{
xmlDocPtr doc;
xmlNodePtr cur, child;
address = (AddressBook*)malloc(sizeof(AddressBook));
if (filename == NULL)
filename = "addressbook.xml";
/* Parse our addressbook file */
if(!(doc = xmlParseFile(imsua_addpath(filename))))
{
g_warning("Error opening addressbook file: %s", imsua_addpath(filename));
xmlFreeDoc( doc );
return FALSE;
}
if(!(cur = xmlDocGetRootElement(doc)))
{
g_warning("Addressbook document has no root element");
xmlFreeDoc( doc );
return FALSE;
}
if(xmlStrcmp(cur->name, (const xmlChar *) "addressbook" ))
{
g_warning("XML document of the wrong type, root node != addressbook");
xmlFreeDoc( doc );
return FALSE;
}
cur = cur->xmlChildrenNode;
/* Traverse through document looking for our addressbook */
while(cur)
{
if (cur->type == XML_ELEMENT_NODE)
{
if(child = cur->xmlChildrenNode)
{
if(!xmlStrcmp(cur->name, (const xmlChar *)"lastname")){
strcpy(address->lastname, child->content);
printf("Last Name: %s\n", address->lastname);
}
if(!xmlStrcmp(cur->name, (const xmlChar *)"firstname")){
strcpy(address->firstname, child->content);
printf("First Name: %s\n", address->firstname);}
}
}
cur = cur->next;
}
return TRUE;
}
I call addressbook_get_addresses_from_xml_file("addressbook.xml") when the button is clicked and i call
addressbook_set_addresses_dialog() when the window is activated to show
I am not sure what the difference between gtk_entry_set_text and gtk_entry_get_text is. Can someone please
help? I am in need of urgent help...
Thanks
Aakanksha
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20080215/09c573d4/attachment.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]