Beispiel #1
0
        private void _ParseSearchResults(string xml)
        {
            bool        shouldUpdate = false;
            XmlDocument doc          = new XmlDocument();

            doc.LoadXml(xml);
            int docIndex            = 0;
            DocumentTermModel model = new DocumentTermModel();

            foreach (XmlNode node in doc.SelectNodes("/data/result"))
            {
                XmlAttribute titleAtt = node.Attributes["title"];
                XmlAttribute hrefAtt  = node.Attributes["disp"];
                XmlAttribute urlAtt   = node.Attributes["url"];
                XmlAttribute textAtt  = node.Attributes["text"];
                if (titleAtt != null && hrefAtt != null && textAtt != null)
                {
                    string title = titleAtt.Value, href = hrefAtt.Value, text = textAtt.Value, url = urlAtt.Value;
                    if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(href) && !String.IsNullOrEmpty(url))
                    {
                        DownloadResult             result = new DownloadResult(title, href, url, text, docIndex++);
                        DocumentTermModel.Document d      = model.AddDocument(result);
                        foreach (XmlNode catNode in node.SelectNodes("t"))
                        {
                            string tagText = catNode.Attributes["text"].Value;
                            uint   count   = 1;
                            if (catNode.Attributes["c"] != null)
                            {
                                count = Convert.ToUInt32(catNode.Attributes["c"].Value);
                            }
                            if (!String.IsNullOrEmpty(tagText))
                            {
                                model.AddTerm(d, tagText, count);
                            }
                        }
                        _resultList.Add(result);
                        shouldUpdate = true;
                    }
                }
            }
            if (shouldUpdate)
            {
                Dispatcher.Invoke((SimpleDelegate) delegate() {
                    _UpdateUI(model);
                });
            }
        }
Beispiel #2
0
        private void _ParseDelicousXml(string xml)
        {
            bool        shouldUpdate = false;
            XmlDocument doc          = new XmlDocument();

            doc.LoadXml(xml);
            DocumentTermModel model = new DocumentTermModel();
            int docIndex            = 0;

            foreach (XmlNode node in doc.SelectNodes("/rss/channel/item"))
            {
                XmlElement titleAtt = node["title"];
                XmlElement hrefAtt  = node["link"];
                if (titleAtt != null && hrefAtt != null)
                {
                    string title = titleAtt.InnerText, href = hrefAtt.InnerText;
                    if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(href))
                    {
                        DownloadResult             result = new DownloadResult(title, href, docIndex++);
                        DocumentTermModel.Document d      = model.AddDocument(result);
                        foreach (XmlNode catNode in node.SelectNodes("category"))
                        {
                            string text = catNode.InnerText;
                            if (!String.IsNullOrEmpty(text))
                            {
                                model.AddTerm(d, text, 1);
                            }
                        }
                        _resultList.Add(result);
                        shouldUpdate = true;
                    }
                }
            }
            if (shouldUpdate)
            {
                Dispatcher.Invoke((SimpleDelegate) delegate() {
                    _UpdateUI(model);
                });
            }
        }