在做一个新浪微博的客户端,现在将数据以XML形式读入了DataSet<?xml version="1.0" encoding="UTF-8"?>
<statuses>
<status>
<created_at>Tue Nov 30 15:36:28 +0800 2010</created_at>
<id>3979831859</id>
<text>ewvxe</text>
<source>
<a href="">微博开放平台接口</a>
</source>
<favorited>false</favorited>
<truncated>false</truncated>
<geo/>
<in_reply_to_status_id/>
<in_reply_to_user_id/>
<in_reply_to_screen_name/>
<user>
<id>1854740027</id>
<screen_name>siegetest</screen_name>
<name>siegetest</name>
<province>11</province>
<city>8</city>
<location>北京 海淀区</location>
<description>ABCDE</description>
<url/>
<profile_image_url>http://tp4.sinaimg.cn/1854740027/50/0/1</profile_image_url>
<domain/>
<gender>m</gender>
<followers_count>3</followers_count>
<friends_count>20</friends_count>
<statuses_count>15</statuses_count>
<favourites_count>0</favourites_count>
<created_at>Thu Nov 11 00:00:00 +0800 2010</created_at>
<following>false</following>
<verified>false</verified>
<allow_all_act_msg>false</allow_all_act_msg>
<geo_enabled>true</geo_enabled>
</user>
</status>
...
</statuses>
利用DataSet如何获取结点user下的信息呢?
<statuses>
<status>
<created_at>Tue Nov 30 15:36:28 +0800 2010</created_at>
<id>3979831859</id>
<text>ewvxe</text>
<source>
<a href="">微博开放平台接口</a>
</source>
<favorited>false</favorited>
<truncated>false</truncated>
<geo/>
<in_reply_to_status_id/>
<in_reply_to_user_id/>
<in_reply_to_screen_name/>
<user>
<id>1854740027</id>
<screen_name>siegetest</screen_name>
<name>siegetest</name>
<province>11</province>
<city>8</city>
<location>北京 海淀区</location>
<description>ABCDE</description>
<url/>
<profile_image_url>http://tp4.sinaimg.cn/1854740027/50/0/1</profile_image_url>
<domain/>
<gender>m</gender>
<followers_count>3</followers_count>
<friends_count>20</friends_count>
<statuses_count>15</statuses_count>
<favourites_count>0</favourites_count>
<created_at>Thu Nov 11 00:00:00 +0800 2010</created_at>
<following>false</following>
<verified>false</verified>
<allow_all_act_msg>false</allow_all_act_msg>
<geo_enabled>true</geo_enabled>
</user>
</status>
...
</statuses>
利用DataSet如何获取结点user下的信息呢?
ds.ReadXml("");XElement xmlPage = XElement.Load("");
var query = from x in xmlPage.Descendants("user")
select x;
linq to xml
ds.ReadXml("");
var q = from c in doc.Descendants("status")
select new
{
newtext = c.Elements("text"),
newthumbnail_pic = c.Elements("thumbnail_pic"),
newID= c.Elements("id"),
neworiginal_pic = c.Elements("original_pic"),
newcreated_at = c.Elements("created_at"),
newuser_screen_name = c.Elements("user").Elements("screen_name"),
newprofile_image_url = c.Elements("user").Elements("profile_image_url"),
var q = from c in doc.Descendants("status")
select new
{
newtext = c.Elements("text"),
newthumbnail_pic = c.Elements("thumbnail_pic"),
newID= c.Elements("id"),
neworiginal_pic = c.Elements("original_pic"),
newcreated_at = c.Elements("created_at"),
newuser_screen_name = c.Elements("user").Elements("screen_name"),
newprofile_image_url = c.Elements("user").Elements("profile_image_url"),
newsource_a = c.Elements("source").Elements("a"),
newretweeted_text = c.Elements("retweeted_status").Elements("text"),
newretweeted_thumbnail_pic = c.Elements("retweeted_status").Elements("thumbnail_pic"),
newretweeted_original_pic = c.Elements("retweeted_status").Elements("original_pic"),
newretweeted_user_screen_name = c.Elements("retweeted_status").Elements("user").Elements("screen_name"),
newfollowers_count = c.Elements("user").Elements("followers_count"),
newverified=c.Element("user").Elements("verified"),
newsuser = c.Elements("user").Elements("name")
};
int i = 1; foreach (var item in q)
{
Status SinaBlogListEntity = new Status();
SinaBlogListEntity.id = item.newID.First().Value;
SinaBlogListEntity.isfriendblog = SINAAPI.NotFriendBlog;
SinaBlogListEntity.LinkText = SINAAPI.GetLinkAndText(item.newtext.First().Value);
SinaBlogListEntity.text = SINAAPI.ReplaceLinkAndText(item.newtext.First().Value, "【链接】");
SinaBlogListEntity.userinfo = item.newsuser.First().Value; SinaBlogListEntity.created_at = item.newcreated_at.First().Value;
SinaBlogListEntity.created_at = SinaBlogListEntity.created_at.Substring(0,SinaBlogListEntity.created_at.IndexOf('+') - 1);
SinaBlogListEntity.created_at = TimeSpanValue(SinaBlogListEntity.created_at); SinaBlogListEntity.followers_count = item.newfollowers_count.First().Value;
SinaBlogListEntity.user_screen_name = item.newuser_screen_name.First().Value;
SinaBlogListEntity.user_profile_image_url = item.newprofile_image_url.First().Value;
SinaBlogListEntity.source = item.newsource_a.First().Value;