[xml] Strange behavior



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>&lt;a href="" href="http://apiwiki.twitter.com/&quot" target="_blank">http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;</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.jpg profile_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>&lt;a href="" href="http://apiwiki.twitter.com/&quot" target="_blank">http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;</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="" href="http://apiwiki.twitter.com/" target="_blank">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------


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