D'Arcy from Winnipeg
Musings of a Canadian Developer - Silverlight, ASP.NET, BizTalk, Life, and Technology

"Exactly one element is required directly inside the element" Workaround

Friday, March 31, 2006 12:48 PM

I ran into this issue working with the sitemap, and I was banging my head on my desk reading post after post about how you just had to nest everything under a “home” node...until I remember the workaround I did for a previous asp.net 2.0 app.

All the samples out there will tell you that you need to have one root siteMapNode, and this is true. But what if you don't want to show that node? What if you want this to be used for a menu and there needs to be multiple starting points and not just one?

The fix is really simple. Click on your SiteMap Datasource control, and in the properties window you'll see one called:

ShowStartingNode

Set this to false, and voila: the evil root node is no where to be found.

D


Feedback

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

D'Arcy:

I have been banging my head on this one as well. Thanks for your kind post. This was an easy fix. 8/17/2006 12:02 PM | Chris Conte

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

That goes for me too. Thanks for the tip. 9/9/2006 12:15 AM | AL

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Awesome, thanks. Fixed me up too. 3/8/2007 3:03 PM | Andy

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Wow, what a simple of very effective solution. Thanks. 4/25/2007 12:29 AM | Ruald

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Very Simple. Thanks a Lot! 7/2/2007 2:12 AM | FalguniM

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thanks, that helped a lot!
Cheers :] 11/29/2007 1:03 AM | Brinsky

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thanks for the tip! I was banging my head as well before I found your blog. 2/15/2008 2:40 PM | Sandeep

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Hallelujah, you just saved me hours of head-banging! Thanks a million. 2/17/2008 3:24 PM | Steve

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

You have no idea how long I've been fighting with this problem. Thanks so much for the tip. 4/25/2008 7:35 PM | Mario

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

That really helped! To re-iterate what you have said, you still need to have one root siteMapNode in the sitemap file, but that node will be ignored by the SiteMap datasource control, on using the suggested setting. 4/29/2008 3:47 PM | Joe

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

That helps alot!
Thanks dude! 5/5/2008 9:05 PM | Alex

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thanks for the solution 5/12/2008 1:32 AM | Gagan

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

That really help me. Thanks alot 5/15/2008 7:25 AM | Steve

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thanks, this is a simple step that I did not see anywhere else! 5/19/2008 10:24 AM | Cory

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thanks for your posting. I wasted a day attempting to solve this problem. 5/27/2008 9:19 AM | Mark

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thank you! Just what I needed. 6/28/2008 1:10 AM | An American Developer

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

man, that's exactly what I need. I did what you said, BUT, it didnt work to me! It's done to all up there, except to me... :(

This boring message keeps to appears.. could you show me how your web.sitemap got??? 8/2/2008 10:49 PM | anderson

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

hey, I sent you and exactly after that, I got it. Sitemap file continues being the same, i changed its struture.. due to that, it caused error to me.

But, I saw that when you use reference, in a node, to another web.sitemap, this sitedatasource object property doesnt work. I mean:

Page.aspx
------------
<asp:SiteMapDataSource ShowStartingNode=false ID="SiteMapDataSource1" runat="server" />

<dxm:ASPxMenu ID="ASPxMenu1" runat="server" DataSourceID="SiteMapDataSource1">
</dxm:ASPxMenu>

sitemaps 1
-------------
<siteMap>
<siteMapNode url="dmdd" title="dummy">
<siteMapNode url="~/default.aspx" title="fff">
<siteMapNode url="default2.aspx" title="ldffs"/>
</siteMapNode>
<siteMapNode url="~/default3.aspx" title="Home">
<siteMapNode url="~/default4.aspx" title="Homepage" />
</siteMapNode>
<siteMapNode siteMapFile="~/web2.sitemap"></siteMapNode>
</siteMapNode>

</siteMap>


sitemap 2
-------------------
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode title="xxxx">
<siteMapNode url="" title="j77" description="">
<siteMapNode url="" title="jki" description="" />
<siteMapNode url="" title="joioj" description="" />
</siteMapNode>
<siteMapNode url="" title="j8" description="">
<siteMapNode url="" title="jki" description="" />
<siteMapNode url="" title="joioj" description="" />
</siteMapNode>
</siteMapNode>
</siteMap>




:(

8/2/2008 11:03 PM | anderson

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thank you soo much, I've knew there must be a way to do this but couldn't find it. 9/9/2008 3:16 PM | Sean

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thank you, I just needed it and couldnt find solution, THANKS 9/24/2008 12:32 PM | Keso

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

It is really help full for Beginners . Like me

ThaQQQQQQQQQQ............... 4/9/2009 2:53 AM | Pooranan

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Thanks for the post, however your solution addresses the symptom and not the cause. The reason this problem occurs is because there is no containing parent in the sitemap. If the top level has siblings, then the control can't evaluate which item is the top level / first item to show. So, you just need to make sure there is only 1 parent sitemapnode. Hope this was somewhat clear.

Thanks. 5/10/2009 6:42 PM | Buck Dossey

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Buck, did you read the post?

"All the samples out there will tell you that you need to have one root siteMapNode, and this is true. But what if you don't want to show that node? What if you want this to be used for a menu and there needs to be multiple starting points and not just one?"

The problem was that I didn't want the top level node to display...I wanted my top level to be the first group of child nodes under the root. My post addresses the problem and the solution.

If you were referring to something else (a comment on this post or something else), it wasn't clear.

D 5/10/2009 8:43 PM | D'Arcy from Winnipeg

# re: "Exactly one <siteMapNode> element is required directly inside the <siteMap> element" Workaround

Many Thanks for the workaround!!! Ditto re: headbanging.......

I'm re-developing the above site, moving to ASP.NET. Your help is greatly appreciated. 11/19/2009 5:38 AM | Ken S

Post a comment