SelectSingleNodeNS() 공개 메소드

public SelectSingleNodeNS ( [ xpath, [ namespaces ) : IXmlNode
xpath [
namespaces [
리턴 IXmlNode
예제 #1
0
        private DateTime GetPublishDate(DateTime defaultValue)
        {
            var target = _entryNode.SelectSingleNodeNS("atom:published", _nsMgr.ToNSMethodFormat());

            if (target == null)
            {
                return(defaultValue);
            }
            string val = target.InnerText;

            if (val == null)
            {
                return(defaultValue);
            }
            val = val.Trim();
            if (val.Length == 0)
            {
                return(defaultValue);
            }

            return(ParseRfc3339(val));
        }
        private static string GetNodeValue(XmlElement xml, string xpath)
        {
            var ns = new PropertySet {
                {"root", "http://www.w3.org/2005/Atom"},
                {"media", "http://search.yahoo.com/mrss/"},
                {"openSearch", "http://a9.com/-/spec/opensearchrss/1.0/"}, //"http://a9.com/-/spec/opensearch/1.1/"}, //http://a9.com/-/spec/opensearchrss/1.0/
                {"gd", "http://schemas.google.com/g/2005"},
                {"yt", "http://gdata.youtube.com/schemas/2007"}
            };

            var node = xml.SelectSingleNodeNS(xpath, ns);
            return node == null ? "" : node.InnerText;
        }
예제 #3
0
        /// <summary>
        /// Take the blog post data and put it into the XML node.
        /// </summary>
        protected virtual void Populate(BlogPost post, Uri documentUri, XmlElement node, bool publish)
        {
            AtomEntry atomEntry = new AtomEntry(_atomVer, _atomNS, CategoryScheme, _nsMgr, documentUri, node);

            if (post.IsNew)
            {
                atomEntry.GenerateId();
            }
            atomEntry.Title = post.Title;
            if (Options.SupportsExcerpt && post.Excerpt != null && post.Excerpt.Length > 0)
            {
                atomEntry.Excerpt = post.Excerpt;
            }
            // extra space is to work around AOL Journals XML parsing bug
            atomEntry.ContentHtml = post.Contents + " ";
            if (Options.SupportsCustomDate && post.HasDatePublishedOverride)
            {
                atomEntry.PublishDate = post.DatePublishedOverride;
            }

            if (Options.SupportsCategories)
            {
                atomEntry.ClearCategories();

                foreach (BlogPostCategory cat in post.Categories)
                {
                    if (!BlogPostCategoryNone.IsCategoryNone(cat))
                    {
                        atomEntry.AddCategory(cat);
                    }
                }

                if (Options.SupportsNewCategories)
                {
                    foreach (BlogPostCategory cat in post.NewCategories)
                    {
                        if (!BlogPostCategoryNone.IsCategoryNone(cat))
                        {
                            atomEntry.AddCategory(cat);
                        }
                    }
                }
            }

            if (Options.SupportsPostAsDraft)
            {
                // remove existing draft nodes
                while (true)
                {
                    var draftNode = node.SelectSingleNodeNS(@"app:control/app:draft", _nsMgr.ToNSMethodFormat());
                    if (draftNode == null)
                    {
                        break;
                    }
                    draftNode.ParentNode.RemoveChild(draftNode);
                }

                if (!publish)
                {
                    // ensure control node exists
                    var controlNode = node.SelectSingleNodeNS(@"app:control", _nsMgr.ToNSMethodFormat());
                    if (controlNode == null)
                    {
                        controlNode = node.OwnerDocument.CreateElementNS(_pubNS.Uri, _pubNS.Prefix + ":control");
                        node.AppendChild(controlNode);
                    }
                    // create new draft node
                    XmlElement newDraftNode = node.OwnerDocument.CreateElementNS(_pubNS.Uri, _pubNS.Prefix + ":draft");
                    newDraftNode.InnerText = "yes";
                    controlNode.AppendChild(newDraftNode);
                }
            }

            //post.Categories;
            //post.CommentPolicy;
            //post.CopyFrom;
            //post.Excerpt;
            //post.HasDatePublishedOverride;
            //post.Id;
            //post.IsNew;
            //post.IsTemporary;
            //post.Keywords;
            //post.Link;
            //post.Permalink;
            //post.PingUrls;
            //post.ResetToNewPost;
            //post.TrackbackPolicy;
        }