예제 #1
0
        internal static AtomEntry Parse(XPathNavigator navigator)
        {
            AtomEntry entry = new AtomEntry();

            XPathNavigator    nav  = navigator.Clone();
            XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.All, true);

            while (iter.MoveNext())
            {
                string name = iter.Current.Name.ToLower();
                int    idx  = name.IndexOf(":");
                if (idx != -1)
                {
                    name = name.Split(new char[] { ':' }, 2)[0];
                }

                switch (name)
                {
                case "entry":
                    try
                    {
                        entry.Uri     = FindAlternateUri(iter.Current);
                        entry.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}
                    break;

                case "title":
                    AtomContentConstruct content = AtomContentConstruct.Parse(iter.Current);
                    entry.Title = content;
                    break;

                case "link":
                    entry.Links.Add(AtomLink.Parse(iter.Current));
                    break;

                case "author":
                    entry.Author = AtomPersonConstruct.Parse(iter.Current);
                    break;

                case "contributor":
                    entry.Contributors.Add(AtomPersonConstruct.Parse(iter.Current));
                    break;

                case "id":
                    entry.Id = new Uri(iter.Current.Value);
                    break;

                case "modified":
                    entry.Modified = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "issued":
                    entry.Issued = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "created":
                    entry.Created = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "summary":
                    entry.Summary = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "content":
                    entry.Contents.Add(AtomContent.Parse(iter.Current));
                    break;

                case "dc":
                    entry.AdditionalElements.Add(DcElement.Parse(iter.Current));
                    break;
                }
            }

            return(entry);
        }
예제 #2
0
        internal new static AtomContent Parse(XPathNavigator navigator)
        {
            AtomContent contentElement = new AtomContent();
            string      content        = String.Empty;

            XPathNavigator nav = navigator.Clone();

            // select the element itself
            XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element, true);

            while (iter.MoveNext())
            {
                string name = iter.Current.Name.ToLower();
                int    idx  = name.IndexOf(":");
                if (idx != -1)
                {
                    name = name.Split(new char[] { ':' }, 2)[1];
                }

                switch (name)
                {
                case "content":
                    try
                    {
                        XPathNavigatorReader navReader = new XPathNavigatorReader(nav);
                        string baseUri = navReader.GetAttribute("base", XmlNamespaces.Xml);
                        if (baseUri != null && baseUri.Length > 0)
                        {
                            contentElement.XmlBase = new Uri(baseUri);
                        }
                    }
                    catch {}

                    try
                    {
                        contentElement.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}
                    contentElement.LocalName = name;
                    XPathNavigatorReader reader = new XPathNavigatorReader(iter.Current);
                    reader.Read();
                    content = reader.ReadInnerXml();
                    break;
                }
            }

            // select the attributes
            iter = nav.Select("@*");
            do
            {
                switch (iter.Current.Name.ToLower())
                {
                case "type":
                    contentElement.Type = Utils.Utils.ParseMediaType(
                        iter.Current.Value);
                    break;

                case "mode":
                {
                    switch (iter.Current.Value.ToLower())
                    {
                    case "escaped":
                        contentElement.Mode = Mode.Escaped;
                        break;

                    case "base64":
                        contentElement.Mode = Mode.Base64;
                        break;
                    }
                    break;
                }
                }
            } while(iter.MoveNext());

            switch (contentElement.Mode)
            {
            case Mode.Escaped:
                content = Utils.Utils.Unescape(content);
                break;

            case Mode.Base64:
                content = Encoding.Unicode.GetString(
                    Utils.Utils.Base64Decode(content));
                break;
            }

            contentElement.Content = content;
            return(contentElement);
        }