Developer forum

Forum » Development » How to add attributes in Page xml

How to add attributes in Page xml


Reply
The standard Page xml output is not fetching all attributes.

Is it possible to add i.e. CreatedDate attribute to Page navigation xml output ?

Replies

 
Nicolai Høeg Pedersen
Reply
This article also discusses how to add your own attributes to the navigation output:

http://devierkoeden.com/Articles/[articleId/12]/Extending-the-Google-Sitemap-Feature-with-Custom-Content.aspx

Look for the header "Extending the Sitemap Output"
 
Reply

Tak for input NP :)

Her er løsningen:

[AddInOrder(-1)]
    public class ExtendedSitemap : NavigationProvider
    {
        public override void ProcessTree(RootNavigationItem rootNode, XMLNavigation.NavigationType navigationType)
        {
            if (navigationType == XMLNavigation.NavigationType.Sitemap)
            {  
                List<NavigationItem> nodeList = rootNode.ChildNodes;
                int elements = nodeList.Count;

                for (int i = 0; i < elements; i++)
                {
                    DataSet ds = Database.getDataSet("SELECT * FROM [Page] WHERE PageID = " + Database.SQLEscapeInjection(nodeList[i].ID.ToString()), "Dynamic.mdb");
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count != 0)
                        {
                            ExtendedPageNavigationItem eni = new ExtendedPageNavigationItem
                            {
                                AllowClick = (bool)ds.Tables[0].Rows[0]["PageAllowclick"],
                                AreaID = (int)ds.Tables[0].Rows[0]["PageAreaID"],
                                CreatedDate = (DateTime)ds.Tables[0].Rows[0]["PageCreatedDate"],
                                FriendlyHref = "Default.aspx?ID=" + ds.Tables[0].Rows[0]["PageID"].ToString(),
                                GalleryImage = "files/" + ds.Tables[0].Rows[0]["PageMenuLogoImage"].ToString().Replace("../", ""),
                                Href = "Default.aspx?ID=" + ds.Tables[0].Rows[0]["PageID"].ToString(),
                                ID = nodeList[i].ID,
                                MenuText = ds.Tables[0].Rows[0]["PageMenuText"].ToString(),
                                ShowInSiteMap = (bool)ds.Tables[0].Rows[0]["PageShowInSitemap"],
                                Sort = (int)ds.Tables[0].Rows[0]["PageSort"],
                                Title = ds.Tables[0].Rows[0]["PageMetaTitle"].ToString(),
                            };

                            nodeList.Add(eni);
                        }
                    }
                }

                nodeList.RemoveRange(0, elements);
            }
        }
    }

    public class ExtendedPageNavigationItem : PageNavigationItem
    {
        [AddInName("GalleryImage")]
        public string GalleryImage { get; set; }

        [AddInName("CreatedDate")]
        public DateTime CreatedDate { get; set; }
    }

 
Nicolai Høeg Pedersen
Reply
Thanks for sharing...

Can't help notice the potential performance problem when querying the database inside a loop...

If it is only done when displaying a paragraph with the sitemap, its ok. Otherwise it could be an issue.
 
Reply
Yeeah i noticed that as well.

I have check the output, it only replaces the sitemap elements :)
 
Reply
>> Can't help notice the potential performance problem when querying the database inside a loop...

Yeah, I was just going to say something similar ;-)

You could loop through the list, collect the IDs and then fire a single SELECT statement Alternatively, you could cache the data in the .NET cache, putting a time-based or a database expiration policy on it so it gets refresh at certain intervals, or when the data changes.

Cheers,

Imar


 

You must be logged in to post in the forum