Beispiel #1
0
        private void ConvertToRes(XmlDocument data)
        {
            XmlNodeList list = data.GetElementsByTagName("NbaNomalDetailObj");

            for (uint i = 0; i < list.Length; i++)
            {
                IXmlNode item    = list.Item(i);
                string   player1 = item.SelectSingleNode("player1").InnerText;
                string   player2 = item.SelectSingleNode("player2").InnerText;
                string   score   = item.SelectSingleNode("score").InnerText;
                string   status  = item.SelectSingleNode("status").InnerText;
                string   time    = item.SelectSingleNode("time").InnerText;
                if (status == "1")
                {
                    status = "直播中";
                }
                else if (status == "2")
                {
                    status = "已结束";
                }
                else
                {
                    status = "未开赛";
                }
                string res = time + " " + player1 + score + player2 + " " + status + "\n\n";
                result.Text += res;
            }
        }
Beispiel #2
0
        private void ExtractStandardPostFields(IXmlNode postNode, BlogPost blogPost)
        {
            // post id
            blogPost.Id = NodeText(postNode.SelectSingleNode("member[name='postId']/value"));

            // contents and title
            ParsePostContent(postNode.SelectSingleNode("member[name='content']/value"), blogPost);

            // date published
            blogPost.DatePublished = ParseBlogDate(postNode.SelectSingleNode("member[name='dateCreated']/value"));
        }
Beispiel #3
0
 private void LoadConferenceData(IXmlNode nodeConference)
 {
     Conference.Title = nodeConference.SelectSingleNode("title").InnerText;
     Conference.Subtitle = nodeConference.SelectSingleNode("subtitle").InnerText;
     Conference.Venue = nodeConference.SelectSingleNode("venue").InnerText;
     Conference.City = nodeConference.SelectSingleNode("city").InnerText;
     Conference.Start = DateTime.Parse(nodeConference.SelectSingleNode("start").InnerText);
     Conference.End = DateTime.Parse(nodeConference.SelectSingleNode("end").InnerText);
     Conference.NumberOfDays = int.Parse(nodeConference.SelectSingleNode("days").InnerText);
     Conference.DayChange = TimeSpan.Parse(nodeConference.SelectSingleNode("day_change").InnerText);
     Conference.TimeslotDuration = TimeSpan.Parse(nodeConference.SelectSingleNode("timeslot_duration").InnerText);
 }
        public static DateTime?GetDate(IXmlNode el, string xpath, XmlNamespaceManager nsMgr, Uri documentUri)
        {
            if (el == null)
            {
                return(null);
            }
            var node = nsMgr == null
                ? el.SelectSingleNode(xpath)
                : el.SelectSingleNodeNS(xpath, nsMgr.DefaultNamespace);

            if (node == null)
            {
                return(null);
            }
            string rawDate = node.NodeValue.ToString(); // example: 2010-04-02T18:02:55Z

            if (String.IsNullOrEmpty(rawDate))
            {
                return(null);
            }

            DateTime dateTime;

            if (DateTime.TryParse(rawDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
            {
                return(dateTime);
            }

            return(null);
        }
Beispiel #5
0
        public Survey(IXmlNode s)
        {
            this.surveyName = s.SelectSingleNode("descendant::surveyname").InnerText;

            surveyQuestionList = new ObservableCollection <surveyQuestion>();
            var questions = s.SelectSingleNode("descendant::questions").SelectNodes("descendant::question");

            foreach (var q in questions)
            {
                string         t  = q.SelectSingleNode("descendant::text").InnerText;
                string         id = q.SelectSingleNode("descendant::id").InnerText;
                surveyQuestion a  = new surveyQuestion {
                    questionID = Convert.ToInt16(id), questionText = t
                };
                surveyQuestionList.Add(a);
            }
        }
Beispiel #6
0
        private void ParsePostContent(IXmlNode xmlNode, BlogPost blogPost)
        {
            // get raw content (decode base64 if necessary)
            string content;
            var    base64Node = xmlNode.SelectSingleNode("base64");

            if (base64Node != null)
            {
                byte[] contentBytes = Convert.FromBase64String(base64Node.InnerText);
                content = _utf8EncodingNoBOM.GetString(contentBytes);
            }
            else // no base64 encoding, just read text
            {
                content = xmlNode.InnerText;
            }

            // parse out the title and contents of the post
            HtmlExtractor ex = new HtmlExtractor(content);

            if (ex.Seek("<title>").Success)
            {
                SetPostTitleFromXmlValue(blogPost, ex.CollectTextUntil("title"));
                content = content.Substring(ex.Parser.Position).TrimStart('\r', '\n');
            }

            if (content.Trim() != string.Empty)
            {
                HtmlExtractor ex2 = new HtmlExtractor(content);
                if (Options.SupportsExtendedEntries && ex2.Seek("<lj-cut>").Success)
                {
                    blogPost.SetContents(content.Substring(0, ex2.Element.Offset), content.Substring(ex2.Element.Offset + ex2.Element.Length));
                }
                else
                {
                    blogPost.Contents = content;
                }
            }
        }
        public BlogProviderFromXml(IXmlNode providerNode)
        {
            string id = NodeText(providerNode.SelectSingleNode("id"));

            if (id.Length == 0)
            {
                throw new ArgumentException("Missing Id parameter");
            }

            string name = NodeText(providerNode.SelectSingleNode("name"));

            if (name.Length == 0)
            {
                throw new ArgumentException("Missing Name parameter");
            }

            string description = NodeText(providerNode.SelectSingleNode("description"));

            string link = NodeText(providerNode.SelectSingleNode("link"));

            string clientType = NodeText(providerNode.SelectSingleNode("clientType"));

            if (clientType.Length == 0)
            {
                throw new ArgumentException("Missing ClientType parameter");
            }
            //if ( !BlogClientManager.IsValidClientType(clientType) )
            //	throw new ArgumentException("Invalid ClientType: " + clientType) ;

            string postApiUrl = NodeText(providerNode.SelectSingleNode("postApiUrl"));

            if (postApiUrl.Length == 0)
            {
                throw new ArgumentException("Invalid PostApiUrl");
            }

            // visibiilty flag
            bool visible = BlogClientOptions.ReadBool(NodeText(providerNode.SelectSingleNode("visible")), true);;

            // auto-detection
            string homepageUrlPattern     = NodeText(providerNode.SelectSingleNode("homepageUrlPattern"));
            string homepageContentPattern = NodeText(providerNode.SelectSingleNode("homepageContentPattern"));
            string rsdEngineNamePattern   = NodeText(providerNode.SelectSingleNode("rsdEngineNamePattern"));
            string rsdHomepageLinkPattern = NodeText(providerNode.SelectSingleNode("rsdHomepageLinkPattern"));

            // rsd client type mappings
            ArrayList rsdClientTypeMappings = new ArrayList();
            var       mappingNodes          = providerNode.SelectNodes("rsdClientTypeMappings/mapping");

            foreach (var mappingNode in mappingNodes)
            {
                string rsdClientType    = NodeText(mappingNode.SelectSingleNode("@rsdClientType"));
                string writerClientType = NodeText(mappingNode.SelectSingleNode("@clientType"));
                if (rsdClientType != String.Empty && writerClientType != String.Empty)
                {
                    rsdClientTypeMappings.Add(new RsdClientTypeMapping(rsdClientType, writerClientType));
                }
            }

            // provider faults
            ArrayList providerFaults = new ArrayList();
            var       faultNodes     = providerNode.SelectNodes("faults/fault");

            foreach (var faultNode in faultNodes)
            {
                string codePattern   = NodeText(faultNode.SelectSingleNode("codePattern"));
                string stringPattern = NodeText(faultNode.SelectSingleNode("stringPattern"));
                string messageId     = NodeText(faultNode.SelectSingleNode("messageId"));
                if (messageId != String.Empty)
                {
                    providerFaults.Add(new ProviderFault(codePattern, stringPattern, messageId));
                }
            }


            // parse options (create generic options object to populate defaults)
            var optionsNode = providerNode.SelectSingleNode("options");

            foreach (var node in optionsNode.ChildNodes)
            {
                if (node.NodeType == NodeType.ElementNode)
                {
                    if (_options.ContainsKey(node.NodeName))
                    {
                        _options.Remove(node.NodeName);
                    }
                    _options.Add(node.NodeName, node.InnerText.Trim());
                }
            }

            StringId   postApiUrlLabel           = StringId.CWSelectProviderApiUrlLabel;
            XmlElement postApiUrlDescriptionNode = providerNode.SelectSingleNode("postApiUrlLabel") as XmlElement;

            if (postApiUrlDescriptionNode != null)
            {
                try
                {
                    postApiUrlLabel = (StringId)Enum.Parse(
                        typeof(StringId),
                        "CWSelectProviderApiUrlLabel_" + postApiUrlDescriptionNode.InnerText,
                        false);
                }
                catch
                {
                    Debug.Fail("Invalid value for postApiUrlLabel");
                }
            }

            string appid     = null;
            var    appIdNode = providerNode.SelectSingleNode("appid/text()");

            if (appIdNode != null && !string.IsNullOrEmpty((string)appIdNode.NodeValue))
            {
                appid = (string)appIdNode.NodeValue;
            }

            // initialize
            Init(id, name, description, link, clientType, postApiUrl, postApiUrlLabel, appid,
                 homepageUrlPattern, homepageContentPattern,
                 rsdClientTypeMappings.ToArray(typeof(RsdClientTypeMapping)) as RsdClientTypeMapping[],
                 rsdEngineNamePattern, rsdHomepageLinkPattern,
                 providerFaults.ToArray(typeof(ProviderFault)) as ProviderFault[],
                 visible);
        }
Beispiel #8
0
        public async void LerFeedEpisodios(string v_sURLFeed)
        {
            try
            {
                p_objListaFeedEpisodio = new List <FeedEpisodio>();
                SyndicationClient objSyndcationClient = new SyndicationClient();
                Uri             objFeedUri            = new Uri(v_sURLFeed);
                SyndicationFeed objSyndicationFeed    = await objSyndcationClient.RetrieveFeedAsync(objFeedUri);

                FeedPodcast objFeedPodcast = new FeedPodcast();

                foreach (SyndicationItem item in objSyndicationFeed.Items)
                {
                    FeedEpisodio objFeedEpi = new FeedEpisodio();
                    objFeedEpi.Titulo         = item.Title.Text;
                    objFeedEpi.DataPublicacao = item.PublishedDate.DateTime.ToString();
                    if (objSyndicationFeed.SourceFormat == SyndicationFormat.Atom10)
                    {
                        objFeedEpi.Descricao = item.Content.Text;
                        objFeedEpi.URLSite   = "";
                    }
                    if (objSyndicationFeed.SourceFormat == SyndicationFormat.Rss20)
                    {
                        IXmlNode    xmlNodeSelect;
                        XmlDocument xmlDoc      = item.GetXmlDocument(SyndicationFormat.Rss20);
                        IXmlNode    xmlNodeItem = xmlDoc.GetElementsByTagName("item")[0];
                        //link
                        if (item != null)
                        {
                            if (item.Links[0] != null)
                            {
                                objFeedEpi.URLSite = item.Links[0].Uri.ToString();
                            }
                        }
                        //descrição
                        xmlNodeSelect = xmlNodeItem.SelectSingleNode("description");
                        if (xmlNodeSelect != null)
                        {
                            if (xmlNodeSelect.ChildNodes[0] != null)
                            {
                                if (xmlNodeSelect.ChildNodes[0].NodeValue != null)
                                {
                                    objFeedEpi.Descricao = xmlNodeSelect.ChildNodes[0].NodeValue.ToString();
                                }
                            }
                        }

                        // mp3
                        xmlNodeSelect = xmlNodeItem.SelectSingleNode("enclosure");
                        if (xmlNodeSelect != null)
                        {
                            if (xmlNodeSelect.Attributes[0] != null)
                            {
                                if (xmlNodeSelect.Attributes[0].NodeValue != null)
                                {
                                    objFeedEpi.URLMp3 = xmlNodeSelect.Attributes[0].NodeValue.ToString();
                                }
                            }
                        }
                        // para testes:
                        //string x = xmlNodeItem.GetXml();

                        if (xmlNodeItem != null)
                        {
                            int iQtd = xmlNodeItem.ChildNodes.Count;
                            for (int i = 0; i < iQtd; i++)
                            {
                                // duração
                                if (xmlNodeItem.ChildNodes[i].NodeName.ToLower().ToString() == "duration")
                                {
                                    if (xmlNodeItem.ChildNodes[i] != null)
                                    {
                                        if (xmlNodeItem.ChildNodes[i].ChildNodes[0] != null)
                                        {
                                            objFeedEpi.Duracao = xmlNodeItem.ChildNodes[i].ChildNodes[0].NodeValue.ToString();
                                        }
                                    }
                                }
                                // imagem
                                if (xmlNodeItem.ChildNodes[i].NodeName.ToLower().ToString() == "image")
                                {
                                    if (xmlNodeItem.ChildNodes[i] != null)
                                    {
                                        if (xmlNodeItem.ChildNodes[i].Attributes[0] != null)
                                        {
                                            objFeedEpi.URLImagem = xmlNodeItem.ChildNodes[i].Attributes[0].NodeValue.ToString();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (String.IsNullOrEmpty(objFeedEpi.URLMp3) == false) // previne de adicionar o que não é podcast
                    {
                        p_objListaFeedEpisodio.Add(objFeedEpi);
                    }
                }
                if (AoLerFeedEpisodio != null)
                {
                    AoLerFeedEpisodio(p_objListaFeedEpisodio);
                }
            }
            catch (Exception e)
            {
                if (AoGerarErro != null)
                {
                    AoGerarErro("Erro ao ler feed de episódios podcast.\n" + e.ToString());
                }
            }
        }
        public static string GetUrl(IXmlNode el, string xpath, XmlNamespaceManager nsMgr, Uri documentUri)
        {
            if (el == null)
            {
                return(null);
            }
            var node = nsMgr == null
                ? el.SelectSingleNode(xpath)
                : el.SelectSingleNodeNS(xpath, nsMgr.DefaultNamespace);

            if (node == null)
            {
                return(null);
            }
            string rawUrl = node.NodeValue.ToString();

            if (rawUrl == null || rawUrl.Length == 0)
            {
                return(null);
            }

            // optimize for common case of absolute path
            if (rawUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    return(UrlHelper.SafeToAbsoluteUri(new Uri(rawUrl)));
                }
                catch { }
            }

            ArrayList ancestors = new ArrayList();

            var parent = node.ParentNode;

            while (parent != null)
            {
                ancestors.Add(parent);
                parent = parent.ParentNode;
            }

            ancestors.Reverse();

            Uri uri = documentUri;

            foreach (var anc in ancestors)
            {
                if (anc is XmlElement)
                {
                    XmlElement baseEl = (XmlElement)anc;
                    if (baseEl.Attributes.Any(a => a.LocalName == "xml:base"))
                    {
                        string thisUri = baseEl.GetAttribute("xml:base");
                        if (uri == null)
                        {
                            uri = new Uri(thisUri);
                        }
                        else
                        {
                            uri = new Uri(uri, thisUri);
                        }
                    }
                }
            }

            if (uri == null)
            {
                return(UrlHelper.SafeToAbsoluteUri(new Uri(rawUrl)));
            }
            else
            {
                return(UrlHelper.SafeToAbsoluteUri(new Uri(uri, rawUrl)));
            }
        }
 private void noReadFeedItemXml(IXmlNode itemXml) {
     itemXml.SelectSingleNode("isread").InnerText = "false";
 }
 private void readedFeedItemXml(IXmlNode itemXml) {
     itemXml.SelectSingleNode("isread").InnerText = "true";
 }
            private static AtomContentValue ToTextValue(IXmlNode node)
            {
                string type = (string)node.Attributes.SingleOrDefault(a => a.NodeName == "type").NodeValue;

                string mode = (string)node.Attributes.SingleOrDefault(a => a.NodeName == "mode")?.NodeValue;

                if (string.IsNullOrEmpty(mode))
                {
                    mode = "xml";
                }

                string content;

                switch (mode)
                {
                case "escaped":
                    content = node.InnerText;
                    break;

                case "base64":
                    content = Encoding.UTF8.GetString(Convert.FromBase64String((string)node.NodeValue));
                    break;

                default:
                case "xml":
                    content = node.InnerText;
                    if (type == string.Empty && node.SelectSingleNode("./*") != null)
                    {
                        type = "application/xhtml+xml";
                    }
                    break;
                }

                AtomContentValue tv;

                switch (type)
                {
                case "text/html":
                    tv = new AtomContentValue(AtomContentValueType.HTML, content);
                    break;

                case "application/xhtml+xml":
                    XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
                    nsMgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

                    if (mode == "xml")
                    {
                        var div = node.SelectSingleNodeNS("xhtml:div", nsMgr.ToNSMethodFormat());
                        if (div != null)
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, (string)div.NodeValue);
                        }
                        else
                        {
                            tv = new AtomContentValue(AtomContentValueType.XHTML, string.Empty);
                        }
                    }
                    else
                    {
                        tv = new AtomContentValue(AtomContentValueType.XHTML, content);
                    }
                    break;

                default:
                case "text/plain":
                    tv = new AtomContentValue(AtomContentValueType.Text, content);
                    break;
                }
                return(tv);
            }
Beispiel #13
0
        private void LoadConferenceEventData(IXmlNode nodeEvent, Day day, Room room)
        {
            Event conferenceEvent = new Event();
            conferenceEvent.Id = nodeEvent.Attributes.GetNamedItem("id").InnerText;
            conferenceEvent.Start = day.Date.Add(DateTime.Parse(nodeEvent.SelectSingleNode("start").InnerText).TimeOfDay);
            conferenceEvent.Duration = TimeSpan.Parse(nodeEvent.SelectSingleNode("duration").InnerText);
            conferenceEvent.Room = room;
            conferenceEvent.Day = day;
            conferenceEvent.Slug = nodeEvent.SelectSingleNode("slug").InnerText;
            conferenceEvent.Title = nodeEvent.SelectSingleNode("title").InnerText;
            conferenceEvent.Subtitle = nodeEvent.SelectSingleNode("subtitle").InnerText;
            string trackName = nodeEvent.SelectSingleNode("track").InnerText;
            conferenceEvent.Track = Conference.Tracks.FirstOrDefault(item => item.Name == trackName);
            if (conferenceEvent.Track == null)
            {
                conferenceEvent.Track = new Track() { Name = trackName };
                Conference.Tracks.Add(conferenceEvent.Track);
            }
            string typeName = nodeEvent.SelectSingleNode("type").InnerText;
            conferenceEvent.Type = Conference.EventTypes.FirstOrDefault(item => item.Name == typeName);
            if (conferenceEvent.Type == null)
            {
                conferenceEvent.Type = new EventType() { Name = typeName };
                Conference.EventTypes.Add(conferenceEvent.Type);
            }
            conferenceEvent.Language = nodeEvent.SelectSingleNode("language").InnerText;
            conferenceEvent.Abstract = nodeEvent.SelectSingleNode("abstract").InnerText;
            conferenceEvent.Description = nodeEvent.SelectSingleNode("description").InnerText;

            conferenceEvent.Persons = new List<Person>();
            IXmlNode nodesPersons = nodeEvent.SelectSingleNode("persons");
            XmlNodeList nodesPersonList = nodesPersons.SelectNodes("person");
            foreach (IXmlNode item in nodesPersonList)
            {
                Person person = LoadConferencePersonData(item);
                conferenceEvent.Persons.Add(person);
            }

            conferenceEvent.Links = new List<Link>();
            IXmlNode nodesLinks = nodeEvent.SelectSingleNode("links");
            XmlNodeList nodesLinkList = nodesLinks.SelectNodes("link");
            foreach (IXmlNode item in nodesLinkList)
            {
                Link link = new Link();
                link.Name = item.InnerText;
                link.Url = item.Attributes.GetNamedItem("href").InnerText;
                conferenceEvent.Links.Add(link);
            }

            Conference.Events.Add(conferenceEvent);
        }