Re: [xml] Strange behavior
- From: Andreas Wagner <andreaswagner7 gmail com>
- To: xml gnome org
- Subject: Re: [xml] Strange behavior
- Date: Wed, 20 Jan 2010 14:23:12 +0100
Hi Gabriel,
have you tried what i send u the last time?
doc = xmlParseFile("TwittXML.xml");
cur = xmlDocGetRootElement(doc);
// ADD this
if ((!xmlStrcmp(cur->name, (const xmlChar *)"statuses"))){
cur = xmlFirstElementChild(cur);
}
cur = cur->xmlFirstElementChild(cur);
while(cur != NULL)
{
if(cur->type == XML_ELEMENT_NODE)
{
parseCD(doc,cur);
}
cur = cur->next;
}
xmlFreeDoc(doc);
return 0;
Regards Andreas
2010/1/6, Gabriel Duarte <confusosk8 gmail com>:
I'm still having the same problem :S
Please, I need help!
I'll attach my program and the XML output...
On Mon, Jan 4, 2010 at 4:29 PM, Gabriel Duarte <confusosk8 gmail com> wrote:
---------- Forwarded message ----------
From: Gabriel Duarte <confusosk8 gmail com>
Date: Sat, Jan 2, 2010 at 6:54 PM
Subject: Strange behavior
To: xml gnome org
Hello! I'm new to libxml, following the instructions and reading examples
I
could parse a XML file perfectly, but now I got a problem I can't solve by
my self.
I got this following XML file:
<?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>Sat Jan 02 20:44:54 +0000 2010</created_at>
<id>7309338854</id>
<text>TESTE_AGAIN</text>
<source><a href="http://apiwiki.twitter.com/"
rel="nofollow">API</a></source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name></in_reply_to_screen_name>
<user>
<id>13672792</id>
<name>Gabriel Duarte</name>
<screen_name>biiielduarte</screen_name>
<location>Rio de Janeiro</location>
<description>Just me! Let's have lots of fun!</description>
<profile_image_url>
http://a1.twimg.com/profile_images/539180228/mau_normal.png
</profile_image_url>
<url>http://kinuxlinux.org/gabriel_duarte</url>
<protected>false</protected>
<followers_count>92</followers_count>
<profile_background_color>742E00</profile_background_color>
<profile_text_color>501E02</profile_text_color>
<profile_link_color>533117</profile_link_color>
<profile_sidebar_fill_color>B7957B</profile_sidebar_fill_color>
<profile_sidebar_border_color>B7957B</profile_sidebar_border_color>
<friends_count>79</friends_count>
<created_at>Tue Feb 19 14:16:41 +0000 2008</created_at>
<favourites_count>2</favourites_count>
<utc_offset>-10800</utc_offset>
<time_zone>Brasilia</time_zone>
<profile_background_image_url>
http://a1.twimg.com/profile_background_images/58350922/bg.jpg
</profile_background_image_url>
<profile_background_tile>true</profile_background_tile>
<notifications>false</notifications>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following>false</following>
<statuses_count>830</statuses_count>
</user>
<geo/>
</status>
The output is:
id : 13672792 name : Gabriel Duarte screen_name : biiielduarte location :
Rio de Janeiro description : Just me! Let's have lots of fun!
profile_image_url :
http://a1.twimg.com/profile_images/539180228/mau_normal.png url :
http://kinuxlinux.org/gabriel_duarte protected : false followers_count :
92 profile_background_color : 742E00 profile_text_color : 501E02
profile_link_color : 533117 profile_sidebar_fill_color : B7957B
profile_sidebar_border_color : B7957B friends_count : 79 created_at : Tue
Feb 19 14:16:41 +0000 2008 favourites_count : 2 utc_offset : -10800
time_zone : Brasilia profile_background_image_url :
http://a1.twimg.com/profile_background_images/58350922/bg.jpgprofile_background_tile
: true notifications : false geo_enabled : false
verified : false following : false statuses_count : 830
I can parser and print the output perfectly, but when I try to use another
file:
<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
<created_at>Sat Jan 02 20:44:54 +0000 2010</created_at>
<id>7309338854</id>
<text>TESTE_AGAIN</text>
<source><a href="http://apiwiki.twitter.com/"
rel="nofollow">API</a></source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name></in_reply_to_screen_name>
<user>
<id>13672792</id>
<name>Gabriel Duarte</name>
<screen_name>biiielduarte</screen_name>
<location>Rio de Janeiro</location>
<description>Just me! Let's have lots of fun!</description>
<profile_image_url>
http://a1.twimg.com/profile_images/539180228/mau_normal.png
</profile_image_url>
<url>http://kinuxlinux.org/gabriel_duarte</url>
<protected>false</protected>
<followers_count>92</followers_count>
<profile_background_color>742E00</profile_background_color>
<profile_text_color>501E02</profile_text_color>
<profile_link_color>533117</profile_link_color>
<profile_sidebar_fill_color>B7957B</profile_sidebar_fill_color>
<profile_sidebar_border_color>B7957B</profile_sidebar_border_color>
<friends_count>79</friends_count>
<created_at>Tue Feb 19 14:16:41 +0000 2008</created_at>
<favourites_count>2</favourites_count>
<utc_offset>-10800</utc_offset>
<time_zone>Brasilia</time_zone>
<profile_background_image_url>
http://a1.twimg.com/profile_background_images/58350922/bg.jpg
</profile_background_image_url>
<profile_background_tile>true</profile_background_tile>
<notifications>false</notifications>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following>false</following>
<statuses_count>830</statuses_count>
</user>
<geo/>
</status>
</statuses>
The output is:
created_at : Sat Jan 02 20:44:54 +0000 2010 id : 7309338854 text :
TESTE_AGAIN source : <a href="http://apiwiki.twitter.com/"
rel="nofollow">API</a> truncated : false in_reply_to_status_id : (null)
in_reply_to_user_id : (null) favorited : false in_reply_to_screen_name :
(null) user : geo : (null)
It's almost the same file, only differs at the <statuses> node. I don't
know whats is happening. I need help to finish my project...
The program that parses these XML files is:
#include <stdio.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
void parseCD(xmlDocPtr doc, xmlNodePtr cur)
{
xmlChar* content;
cur = cur->children;
while(cur != NULL)
{
if(cur->type == XML_ELEMENT_NODE)
{
content = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
printf("%s : %s\n",cur->name,content);
xmlFree(content);
/*free(content);*/ /* windows */
content = NULL;
}
cur = cur->next;
}
}
int main()
{
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile("TwittXML.xml");
cur = xmlDocGetRootElement(doc);
cur = cur->children;
while(cur != NULL)
{
if(cur->type == XML_ELEMENT_NODE)
{
parseCD(doc,cur);
}
cur = cur->next;
}
xmlFreeDoc(doc);
return 0;
}
Thanks!
--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://kinuxlinux.org/gabriel_duarte
Phones:
(55) (21) 9463-7760 /*Mobile*/
(55) (21) 2464-9302 /*Home*/
(55) (21) 2529-5080 /*Work*/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s: a--- C++ UL+++ P L++++ E- W+ N++ o++ K++ w---
O- M- V- PS++ PE++ Y PGP- t++ 5-- X+++ R tv++ b++ DI+ D++
G++ e+ h* r+ y++++
------END GEEK CODE BLOCK------
--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://kinuxlinux.org/gabriel_duarte
Phones:
(55) (21) 9463-7760 /*Mobile*/
(55) (21) 2464-9302 /*Home*/
(55) (21) 2529-5080 /*Work*/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s: a--- C++ UL+++ P L++++ E- W+ N++ o++ K++ w---
O- M- V- PS++ PE++ Y PGP- t++ 5-- X+++ R tv++ b++ DI+ D++
G++ e+ h* r+ y++++
------END GEEK CODE BLOCK------
--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://kinuxlinux.org/gabriel_duarte
Phones:
(55) (21) 9463-7760 /*Mobile*/
(55) (21) 2464-9302 /*Home*/
(55) (21) 2529-5080 /*Work*/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d- s: a--- C++ UL+++ P L++++ E- W+ N++ o++ K++ w---
O- M- V- PS++ PE++ Y PGP- t++ 5-- X+++ R tv++ b++ DI+ D++
G++ e+ h* r+ y++++
------END GEEK CODE BLOCK------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]