Create Top Navigation using XMLDataSource in SharePoint 2013/2016

This SharePoint customization tutorial, we will discuss how to create a top navigation menu by using an XML data source in SharePoint 2013/2016.

Here, the menus will appear from an XML file in SharePoint 2013/2016.

Create Top Navigation using XMLDataSource in SharePoint

For this particular example, I have created a custom master page in SharePoint by simply copy the existing Seattle master page.

The XML file which I have used here is like the below structure.

<?xml version="1.0" encoding="utf-8" ?>
<menu text="Home" url="/sites/EnjoySharePoint/SitePages/Home.aspx">
<menu text="Menu-1" url="/EnjoySharePoint/page1.aspx">
<submenu text="Sub Menu-1" url="/EnjoySharePoint/page2.aspx">
</submenu>
<submenu text="Sub Menu-2" url="/EnjoySharePoint/pag3.aspx">
</submenu>
</menu>
<menu text="Menu-2" url="javascript:void(0);">
<submenu text="Sub Menu-2" url="javascript:void(0);">
<submenu text="Sub Sub Menu-2" url="/EnjoySharePoint/pag4.aspx">
</submenu>
</submenu>
</menu>
</menu>

The file I have stored in the root by putting it using SharePoint designer 2013.

Now Open the SharePoint custom master page and search for below line:

<asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server">

You will find the tag like below:

<asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server">
<SharePoint:AspMenu
ID="TopNavigationMenu"
Runat="server"
EnableViewState="false"
DataSourceID="topSiteMap"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="2"
AdjustForShowStartingNode="true"
MaximumDynamicDisplayLevels="2"
SkipLinkText="" />
</asp:ContentPlaceHolder>

Replace the below tag with the above tag.

<asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server">
<SharePoint:AspMenu
ID="TopNavigationMenu"
Runat="server"
EnableViewState="false"
DataSourceID="xmlTopNavDataSource1"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="2"
AdjustForShowStartingNode="true"
MaximumDynamicDisplayLevels="4"
SkipLinkText=""
StaticSubMenuIndent="0"
CssClass="ms-topNavContainer">
<DataBindings>
<asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="text" NavigateUrlField="url" />
<asp:MenuItemBinding DataMember="SubMenu" NavigateUrlField="url" TextField="text" ValueField="text" />
</DataBindings>
</SharePoint:AspMenu>
<asp:XmlDataSource
ID="xmlTopNavDataSource1"
EnableCaching="false"
DataFile="/sites/EnjoySharePoint/TopNavMenu.xml"
runat="server" />
</asp:ContentPlaceHolder>

Then Save and Publish the SharePoint master page. Then set the SharePoint master page as default master page and once you refresh the page you will be able to see a menu like below:

Create Top Navigation using XMLDataSource in SharePoint

If you have not declared XmlDataSource as Safe, then you may face a Safe control error.

Make sure to declare Safe as True like below on web.config file.

<SafeControl Assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI.WebControls" TypeName="XmlDataSource" Safe="True" AllowRemoteDesigner="True" SafeAgainstScript="False" />

You may like following SharePoint tutorials:

This SharePoint tutorial, we learned how to create a Top Navigation using XMLDataSource in SharePoint 2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com

>