예제 #1
0
        //link
        public static List <NewYorkTime> GetLink()
        {
            List <NewYorkTime> list   = new List <NewYorkTime>();
            StringBuilder      output = new StringBuilder();

            using (XmlReader reader = XmlReader.Create(new StringReader(XmlRss(uri))))
            {
                //item
                while (reader.ReadToDescendant("item"))
                {
                    while (reader.ReadToFollowing("link"))
                    {
                        output.AppendLine(reader.ReadElementContentAsString());
                    }
                }
                string[] ititle = output.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < ititle.Length; i++)
                {
                    NewYorkTime nyt = new NewYorkTime();
                    nyt.itemlink = ititle[i];
                    list.Add(nyt);
                }
            }
            return(list);
        }
예제 #2
0
        //image home
        public static NewYorkTime GetImaggeHome()
        {
            NewYorkTime ny = new NewYorkTime();

            using (XmlReader reader = XmlReader.Create(new StringReader(XmlRss(uri))))
            {
                //Example :
                //  < guid isPermaLink = "true" > https://www.nytimes.com/2017/04/25/us/politics/tax-plan-trump.html</guid>
                //Lay thuoc tinh trong mot the xml

                /*reader.ReadToFollowing("guid");
                 * reader.MoveToFirstAttribute();
                 * string isPermaLink = reader.Value;
                 * ouput.AppendLine(isPermaLink);
                 * aaccc = ouput.ToString();*/

                //image nyt
                while (reader.ReadToDescendant("channel"))
                {
                    reader.ReadToFollowing("url");
                    ny.imgHome = reader.ReadElementContentAsString();
                }
            }
            return(ny);
        }
예제 #3
0
        //image
        public static List <NewYorkTime> GetImage()
        {
            List <NewYorkTime> list   = new List <NewYorkTime>();
            StringBuilder      output = new StringBuilder();

            using (XmlReader reader = XmlReader.Create(new StringReader(XmlRss(uri))))
            {
                //item
                while (reader.ReadToDescendant("item"))
                {
                    while (reader.ReadToFollowing("media:content"))
                    {
                        reader.MoveToFirstAttribute();
                        output.AppendLine(reader.Value);
                    }
                }
                string[] ititle = output.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < ititle.Length; i++)
                {
                    NewYorkTime nyt = new NewYorkTime();
                    nyt.itemimage = ititle[i];
                    list.Add(nyt);
                }
            }
            return(list);
        }
예제 #4
0
        public MainPage()
        {
            this.InitializeComponent();
            List <NewYorkTime> lstNYT = NewYorkTime.listNewYT;

            gridviewNYT.ItemsSource = lstNYT;
            imgHomePage.Source      = new BitmapImage(new Uri(NewYorkTime.GetImaggeHome().imgHome));
        }
예제 #5
0
        public static List <NewYorkTime> GetData()
        {
            List <NewYorkTime> list = new List <NewYorkTime>();

            StringBuilder output = new StringBuilder();
            XDocument     doc    = XDocument.Parse(XmlRss(uri));
            var           result = doc.Root.Attributes().Where(x => x.IsNamespaceDeclaration).
                                   GroupBy(x => x.Name.Namespace == XNamespace.None ? String.Empty : x.Name.LocalName, x => XNamespace.Get(x.Value))
                                   .ToDictionary(x => x.Key, x => x.First());
            XNamespace xnmedia = result["media"];

            foreach (var item in doc.Descendants("item"))
            {
                NewYorkTime ny = new NewYorkTime();
                ny.itemtitle = item.Element("title").Value;
                ny.itemlink  = item.Element("link").Value;
                XNamespace nsc = doc.Root.Attribute(XNamespace.Xmlns + "dc").Value;
                ny.itemdcreator = item.Element(nsc + "creator").Value;
                ny.description  = item.Element("description").Value;
                XElement xemedia = item.Element(xnmedia + "content");
                if (xemedia != null)
                {
                    ny.itemimage = xemedia.Attribute("url").Value;
                }
                else
                {
                    ny.itemimage = "";
                }


                list.Add(ny);
            }



            return(list);
        }