コード例 #1
0
ファイル: XML.cs プロジェクト: jsandip57/PinUrRss
        public List<DataToBind> Retrive(string Data)
        {
            List<DataToBind> list = new List<DataToBind>();
            try
            {
            XDocument doc = XDocument.Parse(Data);
                foreach (XElement ele in doc.Descendants("item"))
                {
                    DataToBind d = new DataToBind();
                    d.Tag = ele.Element("link").Value;
                    d.Content = ele.Element("title").Value;
                    d.Image = "/EasyPin;component/Images/Loading____Please_Wait.png";
                    string destocheck = ele.Element("description").Value;
                    HtmlDocument HTdoc = new HtmlDocument();
                    HTdoc.LoadHtml(destocheck);
                    HTdoc.DetectEncodingHtml(destocheck);
                    if (destocheck.Contains("</img>"))
                    {
                        try
                        {
                            HtmlAttribute att = HTdoc.DocumentNode.Element("//img").Attributes["src"];
                            d.Image = att.Value;
                        }
                        catch
                        {
                            d.Image = "/EasyPin;component/Images/Empty.png";
                        }
                    }
                    else
                    {
                        d.Image = "/EasyPin;component/Images/Empty.png";
                    }

                    d.Pubdate = ele.Element("pubDate").Value;
                    d.Description = HttpUtility.HtmlDecode(HTdoc.DocumentNode.InnerText);
                     list.Add(d);
                }
                return list;
            }
            catch (Exception c)
            {
                list=null;
                return list;
            }
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: jsandip57/PinUrRss
 // STEP4 STEP4 STEP4
 private void ReadWebRequestCallback(IAsyncResult callbackResult)
 {
     try
     {
         HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
         HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
         using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
         {
             string fil = httpwebStreamReader.ReadToEnd();
             int i = 0;
             HtmlDocument doc = new HtmlDocument();
             doc.LoadHtml(fil);
             IEnumerable<HtmlNode> node = doc.DocumentNode.FirstChild.Elements("head");
             if (node != null)
             {
                 List<DataToBind> dat = new List<DataToBind>();
                 IEnumerable<HtmlNode> node1 = doc.DocumentNode.Descendants("div").Where(e => e.Id == "results");
                 foreach (HtmlNode nod1 in node1)
                 {
                     IEnumerable<HtmlNode> node2 = nod1.Descendants("a");
                     DataToBind data = new DataToBind();
                     data.Content = HttpUtility.HtmlDecode(node2.First().InnerText);
                     data.Description = HttpUtility.HtmlDecode(nod1.Descendants("div").ElementAt(2).InnerText);
                     data.Tag = node2.Last().InnerText;
                     dat.Add(data);
                     i++;
                 }
                 Dispatcher.BeginInvoke(() => Loading_for_Search.Visibility = Visibility.Collapsed);
                 Dispatcher.BeginInvoke(() => RssList.Visibility = Visibility.Visible);
                 Dispatcher.BeginInvoke(() => RssList.ItemsSource = dat);
             }
             else
             {
                 Dispatcher.BeginInvoke(() => MessageBox.Show("No results found"));
             }
         }
         myResponse.Close();
     }
     catch (Exception qw)
     {
         Dispatcher.BeginInvoke(() => Loading_for_Search.Visibility = Visibility.Collapsed);
         Dispatcher.BeginInvoke(() => MessageBox.Show("No results found"));
     }
 }