GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 22, 2014 11:56 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Need help to retrieve all elements and attributes from xml
PostPosted: Tue Nov 28, 2006 8:13 pm 
Offline
Familiar Face

Joined: Wed Nov 22, 2006 10:22 pm
Posts: 12
Hi, all.

I am trying to use libxml2 to retrieve all the elements and attributes from a xml file. Through the tutorial in xmlsoft.org, I am able to compile the example code to retrieve A certain element or attribute. Now I want to know how to retrieve ALL elements or attributes in this xml file. Or say how I can walk through the whole xml file and read its content.

Any idea or link for my question?

I know this is not a actual GTK+ question, but waht I wan to do just to read the content from a xml file and load to the CLIST in GTK+. I hope the guru here can help me.

_________________
I am new in GTK+, help me in any way. THANKS!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 2:41 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
It's been a while since I've used libxml2, but if you just need to parse small XML files, GLib provides an XML parser. API docs are available at: http://developer.gnome.org/doc/API/2.0/ ... arser.html

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: Thank you.
PostPosted: Wed Nov 29, 2006 9:49 pm 
Offline
Familiar Face

Joined: Wed Nov 22, 2006 10:22 pm
Posts: 12
Thank you indeed.

Here is the xml sample from xmlsoft.org
Code:
<?xml version="1.0"?>
<story>
  <storyinfo>
    <author>John Fleck</author>
    <datewritten>June 2, 2002</datewritten>
    <keyword>example keyword</keyword>
  </storyinfo>
  <body>
    <headline>This is the headline</headline>
    <para>This is the body text.</para>
  </body>
</story>


Here is the code portion from xmlsoft.org with my modification to display all elements inside:
Code:
void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {

   xmlChar *key;
   cur = cur->xmlChildrenNode;
   while (cur != NULL) {
/*        if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) {
          key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
          printf("keyword: %s\n", key);
          xmlFree(key);
       }
*/
    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
   printf("Element:Name %s\n", cur->name);
    printf("Element Value: %s\n", key);
   cur = cur->next;
   }
    return;
}


Here is the output:
Image

What's wrong with my code?
[/img]

_________________
I am new in GTK+, help me in any way. THANKS!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group