<?xml version="1.0" encoding="UTF-8"?>
<user>
<id>2618525367</id>
<screen_name>xxoo1221</screen_name>
<name>xxoo1221</name>
<province>44</province>
<city>1</city>
<location>广东 广州</location>
<description></description>
<url></url>
<profile_image_url>http://tp4.sinaimg.cn/2618525367/50/0/1</profile_image_url>
<domain></domain>
<gender>m</gender>
<followers_count>0</followers_count>
<friends_count>30</friends_count>
<statuses_count>3</statuses_count>
<favourites_count>0</favourites_count>
<created_at>Thu Feb 16 00:00:00 +0800 2012</created_at>
<following>false</following>
<verified>false</verified>
<allow_all_act_msg>false</allow_all_act_msg>
<geo_enabled>true</geo_enabled>
<status>
<created_at>Sat Feb 18 15:52:46 +0800 2012</created_at>
<id>3414449107283333</id>
<text>我获得微身份勋章啦!我是个有身份的人了,你也快点来领取吧。咱们都是靠谱的人! http://t.cn/zOLVRGV</text>
<source>
<a href="http://badge.weibo.com/">勋章馆</a>
</source>
<favorited>false</favorited>
<truncated>false</truncated>
<geo/>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_screen_name></in_reply_to_screen_name>
<thumbnail_pic>http://ww1.sinaimg.cn/thumbnail/6769a1d2jw1dpykku6qdhj.jpg</thumbnail_pic>
<bmiddle_pic>http://ww1.sinaimg.cn/bmiddle/6769a1d2jw1dpykku6qdhj.jpg</bmiddle_pic>
<original_pic>http://ww1.sinaimg.cn/large/6769a1d2jw1dpykku6qdhj.jpg</original_pic>
<mid>3414449107283333</mid>
</status>
</user>
如题,如代码,取出<id></id>和<screen_name></screen_name>中的值
<user>
<id>2618525367</id>
<screen_name>xxoo1221</screen_name>
<name>xxoo1221</name>
<province>44</province>
<city>1</city>
<location>广东 广州</location>
<description></description>
<url></url>
<profile_image_url>http://tp4.sinaimg.cn/2618525367/50/0/1</profile_image_url>
<domain></domain>
<gender>m</gender>
<followers_count>0</followers_count>
<friends_count>30</friends_count>
<statuses_count>3</statuses_count>
<favourites_count>0</favourites_count>
<created_at>Thu Feb 16 00:00:00 +0800 2012</created_at>
<following>false</following>
<verified>false</verified>
<allow_all_act_msg>false</allow_all_act_msg>
<geo_enabled>true</geo_enabled>
<status>
<created_at>Sat Feb 18 15:52:46 +0800 2012</created_at>
<id>3414449107283333</id>
<text>我获得微身份勋章啦!我是个有身份的人了,你也快点来领取吧。咱们都是靠谱的人! http://t.cn/zOLVRGV</text>
<source>
<a href="http://badge.weibo.com/">勋章馆</a>
</source>
<favorited>false</favorited>
<truncated>false</truncated>
<geo/>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_screen_name></in_reply_to_screen_name>
<thumbnail_pic>http://ww1.sinaimg.cn/thumbnail/6769a1d2jw1dpykku6qdhj.jpg</thumbnail_pic>
<bmiddle_pic>http://ww1.sinaimg.cn/bmiddle/6769a1d2jw1dpykku6qdhj.jpg</bmiddle_pic>
<original_pic>http://ww1.sinaimg.cn/large/6769a1d2jw1dpykku6qdhj.jpg</original_pic>
<mid>3414449107283333</mid>
</status>
</user>
如题,如代码,取出<id></id>和<screen_name></screen_name>中的值
string pattern = @"(?i)<id>\s*?([^<]*)</id>[\s\S]*?<screen_name>\s*?([^<]*)</screen_name>";
Match temp_m = Regex.Match(tempStr,pattern);
string id = temp_m.Groups[1].Value;//2618525367
string screen_name = temp_m.Groups[2].Value;//xxoo1221
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("~/test.xml"));
Response.Write(xmlDoc.DocumentElement["id"].InnerXml + "<br/>");
Response.Write(xmlDoc.DocumentElement["screen_name"].InnerXml);
输出:
2618525367
xxoo1221