LINQ to XML 之 XNamespace

來源:互聯網
上載者:User
 void Main()        {            string xml = @"<feed gd:kind=""buzz#activityFeed"" xmlns=""http://www.w3.org/2005/Atom"" xmlns:activity=""http://activitystrea.ms/spec/1.0/"" xmlns:buzz=""http://schemas.google.com/buzz/2010"" xmlns:crosspost=""http://purl.org/syndication/cross-posting"" xmlns:gd=""http://schemas.google.com/g/2005"" xmlns:georss=""http://www.georss.org/georss"" xmlns:media=""http://search.yahoo.com/mrss/"" xmlns:poco=""http://portablecontacts.net/ns/1.0"" xmlns:thr=""http://purl.org/syndication/thread/1.0"">                              <link rel=""self"" type=""application/atom+xml"" href=""https://www.googleapis.com/buzz/v1/activities/103854838474576564357/@public?alt=atom"" />                              <link rel=""hub"" href=""http://pubsubhubbub.appspot.com/"" />                              <title>Google Buzz Public Feed for ddddddd</title>                              <updated>2010-12-21T13:44:03.083Z</updated>                              <id>tag:google.com,2010:buzz-feed:public:posted:103854838474576564357</id>                              <generator uri=""http://www.google.com/buzz"">Google Buzz</generator>                              <entry gd:kind=""buzz#activity"">                            <title>asdfasdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdf。</title>                            <published>2010-12-21T13:44:02.000Z</published>                            <updated>2010-12-21T13:44:03.083Z</updated>                            <id>tag:google.com,2010:buzz:z125iffjxznzj5pkk23dzhupbwvhzxdep</id>                            <link rel=""alternate"" type=""text/html"" href=""http://www.google.com/buzz/103854838474576564357/3nokvYxiAdf"" />                            <link rel=""self"" type=""application/atom+xml"" href=""https://www.googleapis.com/buzz/v1/activities/103854838474576564357/@self/B:z125iffjxznzj5pkk23dzhupbwvhzxdep?alt=atom"" />                            <link rel=""replies"" type=""application/atom+xml"" href=""https://www.googleapis.com/buzz/v1/activities/103854838474576564357/@self/B:z125iffjxznzj5pkk23dzhupbwvhzxdep/@comments?alt=atom"" thr:count=""0"" thr:updated=""2010-12-21T13:44:03.083Z"" />                            <author>                              <poco:id>103854838474576564357</poco:id>                              <poco:photoUrl />                              <name>ddddddd</name>                              <uri>http://www.google.com/profiles/103854838474576564357</uri>                              <link rel=""photo"" type=""image/jpeg"" href="""" />                              <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>                            </author>                            <content type=""html"">asdfasdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdf。</content>                            <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>                            <activity:object>                              <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>                              <content type=""html"">asdfasdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdf。</content>                              <buzz:original-content type=""text"" />                              <link rel=""alternate"" type=""text/html"" href=""http://www.google.com/buzz/103854838474576564357/3nokvYxiAdf"" />                            </activity:object>                            <source>                              <activity:service>                            <title>www.asdd.com</title>                              </activity:service>                            </source>                            <buzz:visibility>                              <buzz:aclentry type=""group"">                            <poco:id>G:@me:@public</poco:id>                            <uri>https://www.googleapis.com/buzz/v1/people/@me/@groups/G:@me:@public?alt=atom</uri>                            <poco:name>Public</poco:name>                              </buzz:aclentry>                            </buzz:visibility>                            <link rel=""http://schemas.google.com/buzz/2010#liked"" type=""application/poco+xml"" href=""https://www.googleapis.com/buzz/v1/activities/103854838474576564357/@self/B:z125iffjxznzj5pkk23dzhupbwvhzxdep/@liked?alt=atom"" buzz:count=""0"" />                              </entry>                              </feed>";            XElement xmlPage = XElement.Parse(xml);            XNamespace ns = "http://www.w3.org/2005/Atom";            XNamespace buzz = "http://schemas.google.com/buzz/2010";            var query = from x in xmlPage.Descendants("visibility")                        select x.Element("aclentry").Element(ns + "uri").Value;            foreach (var q in query)            {                Console.WriteLine(q);            }            /*https://www.googleapis.com/buzz/v1/people/@me/@groups/G:@me:@public?alt=atom            */        }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.