コード例 #1
0
        private static PagedList <Category> GetCategories(XmlDocument doc)
        {
            PagedList <Category> categories = new PagedList <Category>();

            XmlNode rootNode = doc.SelectSingleNode("/categories");

            categories.PageIndex    = Int32.Parse(rootNode.Attributes["pageIndex"].Value);
            categories.PageSize     = Int32.Parse(rootNode.Attributes["pageSize"].Value);
            categories.TotalRecords = Int32.Parse(rootNode.Attributes["totalCategories"].Value);


            XmlNodeList nodes = doc.SelectNodes("/categories/category");

            foreach (XmlNode node in nodes)
            {
                Category c = GetCategory(node);

                XmlNodeList subCategories = node.SelectNodes("subCategories/category");
                if (subCategories != null)
                {
                    foreach (XmlNode child in subCategories)
                    {
                        c.Children.Add(GetCategory(child));
                    }
                }

                categories.Add(c);
            }


            return(categories);
        }
コード例 #2
0
        private static PagedList <Post> GetPosts(XmlDocument doc)
        {
            PagedList <Post> posts = new PagedList <Post>();

            XmlNode rootNode = doc.SelectSingleNode("/posts");

            posts.PageIndex    = Int32.Parse(rootNode.Attributes["pageIndex"].Value);
            posts.PageSize     = Int32.Parse(rootNode.Attributes["pageSize"].Value);
            posts.TotalRecords = Int32.Parse(rootNode.Attributes["totalPosts"].Value);

            XmlNodeList nodes = doc.SelectNodes("/posts/post");

            foreach (XmlNode node in nodes)
            {
                Post p = new Post();
                p.Id = Int32.Parse(node.Attributes["id"].Value);

                p.Author              = node.SelectSingleNode("author").InnerText;
                p.Body                = node.SelectSingleNode("body").InnerText;
                p.PostBody            = node.SelectSingleNode("postBody").InnerText;
                p.CategoryId          = Int32.Parse(node.SelectSingleNode("categoryId").InnerText);
                p.CommentCount        = Int32.Parse(node.SelectSingleNode("commentCount").InnerText);
                p.PendingCommentCount = Int32.Parse(node.SelectSingleNode("pendingCommentCount").InnerText);
                p.ExtendedBody        = node.SelectSingleNode("extendedBody").InnerText;
                p.PublishDate         = DateTime.Parse(node.SelectSingleNode("publishedDate").InnerText);
                p.ModifiedBy          = node.SelectSingleNode("modifiedBy").InnerText;
                p.ModifiedOn          = DateTime.Parse(node.SelectSingleNode("modifiedOn").InnerText);
                p.CreatedOn           = DateTime.Parse(node.SelectSingleNode("createdOn").InnerText);
                p.Name                = node.SelectSingleNode("name").InnerText;
                p.Status              = Int32.Parse(node.SelectSingleNode("status").InnerText);
                p.Tags                = node.SelectSingleNode("tags").InnerText;
                p.Title               = node.SelectSingleNode("title").InnerText;
                p.Url             = node.SelectSingleNode("url").InnerText;
                p.Views           = Int32.Parse(node.SelectSingleNode("views").InnerText);
                p.IsDeleted       = bool.Parse(node.SelectSingleNode("isDeleted").InnerText);
                p.ContentType     = node.SelectSingleNode("contenttype").InnerText;
                p.SortOrder       = Int32.Parse(node.SelectSingleNode("sortOrder").InnerText);
                p.HomeSortOrder   = Int32.Parse(node.SelectSingleNode("homeSortOrder").InnerText);
                p.ParentId        = Int32.Parse(node.SelectSingleNode("parentId").InnerText);
                p.MetaDescription = node.SelectSingleNode("metaDescription").InnerText;
                p.MetaKeywords    = node.SelectSingleNode("metaKeywords").InnerText;
                p.IsHome          = bool.Parse(node.SelectSingleNode("isHome").InnerText);
                p.EnableComments  = bool.Parse(node.SelectSingleNode("enableComments").InnerText);

                XmlNodeList customFields = node.SelectNodes("customFields/customField");
                foreach (XmlNode cNode in customFields)
                {
                    p.CustomFields[cNode.Attributes["key"].Value] = cNode.InnerText;
                }

                posts.Add(p);
            }


            return(posts);
        }
コード例 #3
0
        private static PagedList <Comment> GetCategories(XmlDocument doc)
        {
            PagedList <Comment> comments = new PagedList <Comment>();

            XmlNode rootNode = doc.SelectSingleNode("/comments");

            comments.PageIndex    = Int32.Parse(rootNode.Attributes["pageIndex"].Value);
            comments.PageSize     = Int32.Parse(rootNode.Attributes["pageSize"].Value);
            comments.TotalRecords = Int32.Parse(rootNode.Attributes["totalComments"].Value);

            XmlNodeList nodes = doc.SelectNodes("/comments/comment");

            foreach (XmlNode node in nodes)
            {
                Comment comment = new Comment();
                comment.Id          = Int32.Parse(node.Attributes["id"].Value);
                comment.PostId      = Int32.Parse(node.Attributes["postId"].Value);
                comment.Body        = node.SelectSingleNode("body").InnerText;
                comment.SpamScore   = Int32.Parse(node.SelectSingleNode("spamScore").InnerText);
                comment.IsPublished = bool.Parse(node.SelectSingleNode("isPublished").InnerText);
                comment.IsTrackback = bool.Parse(node.SelectSingleNode("isTrackback").InnerText);
                comment.IsDeleted   = bool.Parse(node.SelectSingleNode("isDeleted").InnerText);
                comment.Url         = node.SelectSingleNode("url").InnerText;

                XmlNode userName = node.SelectSingleNode("userName");
                if (userName != null)
                {
                    comment.UserName = userName.InnerText;
                }


                XmlNode name = node.SelectSingleNode("name");
                if (name != null)
                {
                    comment.Name = name.InnerText;
                }

                XmlNode email = node.SelectSingleNode("email");
                if (email != null)
                {
                    comment.Email = email.InnerText;
                }

                XmlNode ws = node.SelectSingleNode("webSite");
                if (ws != null)
                {
                    comment.WebSite = ws.InnerText;
                }

                XmlNode ip = node.SelectSingleNode("ipAddress");
                if (ip != null)
                {
                    comment.IPAddress = ip.InnerText;
                }


                comment.Date = DateTime.Parse(node.SelectSingleNode("published").InnerText);

                comments.Add(comment);
            }


            return(comments);
        }