Link to home
Start Free TrialLog in
Avatar of khan2000
khan2000

asked on

siteNavigation

hi

how do i remove "home" from this xml?, if i remove and its throwing me an error:

error:

Exactly one <siteMapNode> element is required directly inside the <siteMap> element.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Configuration.ConfigurationErrorsException: Exactly one <siteMapNode> element is required directly inside the <siteMap> element.

Source Error:

.xml
====
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 
  <siteMapNode url="~/Default.aspx" title="Home">  <<<<<<<<<<<<<<<<< I DO NOT WANT
    <siteMapNode url="~/Books/Default.aspx" title="Books" imageUrl="books.jpg">
      <siteMapNode url="~/Books/Novels.aspx" title="Novels" imageUrl="books.jpg" />
      <siteMapNode url="~/Books/History.aspx" title="History" imageUrl="books.jpg" />
      <siteMapNode url="~/Books/Romance.aspx" title="Romance" imageUrl="Heart.gif" />
    </siteMapNode>
    <siteMapNode url="~/Electronics/Default.aspx" title="Electronics" imageUrl="electronics.jpg" />
    <siteMapNode url="~/DVDs/Default.aspx" title="DVDs" imageUrl="dvd.png" />
    <siteMapNode url="~/Computers/Default.aspx" title="Computers" imageUrl="computer.png" />
  </siteMapNode>
</siteMap>
Avatar of khan2000
khan2000

ASKER

I should be able to put all the nodes in root like this:

http://aspnet.4guysfromrolla.com/images/siteMap.BulletedList1.png
Your structure is confusing me - if you don't want "home", what is going to happen to the nodes inside it (default, books, novels, history, romance...)? Are they all going to be deleted? That is what is happening at the moment, and that is where your error is coming from.

This is the structure as I see it:

      <siteMapNode url="~/Default.aspx" title="Home">      << delete this and all the stuff inside it goes!!
            <siteMapNode url="~/Books/Default.aspx" title="Books" imageUrl="books.jpg">
                  <siteMapNode url="~/Books/Novels.aspx" title="Novels" imageUrl="books.jpg" />
                  <siteMapNode url="~/Books/History.aspx" title="History" imageUrl="books.jpg" />
                  <siteMapNode url="~/Books/Romance.aspx" title="Romance" imageUrl="Heart.gif" />
            </siteMapNode>
            <siteMapNode url="~/Electronics/Default.aspx" title="Electronics" imageUrl="electronics.jpg" />
            <siteMapNode url="~/DVDs/Default.aspx" title="DVDs" imageUrl="dvd.png" />
            <siteMapNode url="~/Computers/Default.aspx" title="Computers" imageUrl="computer.png" />
      </siteMapNode>

Andy
i guess what im saying is, i want all in root rather then all under home:

when i copy and paste ur xml, i get this error:


Top element must be siteMap.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Configuration.ConfigurationErrorsException: Top element must be siteMap.
in other words, i have to have "home" in order to work ?
Sorry, i was not posting a new Xml file for you, I was clarifying the structure with tab indentation.

I am saying that your structure is siteMap --> siteMapNode:Home --> all other siteMapNodes. So, when you delete Home, all of your nodes inside Home are deleted as well. Then you end up with no nodes inside siteMap, and this is giving you the error.

Could you post your code? Then we might be able to help solve your problem.

Andy
well.. i do understand exactly what you saying but again what im sayin is that

can i have sitemapNode like this:

Novels
History
Romance
Electronics

?
Yes, you can. If you post your code I can help you get to it by refactoring your existing code.

Basically, I would get the Nodes collection from the Home node, copy it and add it to the base node, or just move it to the base node, and then delete the Home node.

Andy
here is my xml

   <siteMapNode url="~/Default.aspx" title="Home">
          <siteMapNode url="~/Books/Default.aspx" title="Books" imageUrl="books.jpg">
               <siteMapNode url="~/Books/Novels.aspx" title="Novels" imageUrl="books.jpg" />
               <siteMapNode url="~/Books/History.aspx" title="History" imageUrl="books.jpg" />
               <siteMapNode url="~/Books/Romance.aspx" title="Romance" imageUrl="Heart.gif" />
          </siteMapNode>
          <siteMapNode url="~/Electronics/Default.aspx" title="Electronics" imageUrl="electronics.jpg" />
          <siteMapNode url="~/DVDs/Default.aspx" title="DVDs" imageUrl="dvd.png" />
          <siteMapNode url="~/Computers/Default.aspx" title="Computers" imageUrl="computer.png" />
     </siteMapNode>
OK, I'm sorry I think I've missed an important point :-). Are you doing this by hand? I thought you were doing it programmatically.

In that case try this:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/Books/Default.aspx" title="Books" imageUrl="books.jpg">
      <siteMapNode url="~/Books/Novels.aspx" title="Novels" imageUrl="books.jpg" />
      <siteMapNode url="~/Books/History.aspx" title="History" imageUrl="books.jpg" />
      <siteMapNode url="~/Books/Romance.aspx" title="Romance" imageUrl="Heart.gif" />
    </siteMapNode>
    <siteMapNode url="~/Electronics/Default.aspx" title="Electronics" imageUrl="electronics.jpg" />
    <siteMapNode url="~/DVDs/Default.aspx" title="DVDs" imageUrl="dvd.png" />
    <siteMapNode url="~/Computers/Default.aspx" title="Computers" imageUrl="computer.png" />
</siteMap>
i get this error after i copy and past your code in my website.sitemap


Exactly one <siteMapNode> element is required directly inside the <siteMap> element.
ASKER CERTIFIED SOLUTION
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks AGBrown

i just wanted to double check whether i have to have a root element or not and looks like my doubt is correct
:-) got there in the end
actually you can do that, i was playing with treeview and here is the code for that:

 <asp:TreeView ID="TreeView1" runat="server" Height="248px" Width="232px" ShowCheckBoxes="All">
            <Nodes>
                <asp:TreeNode Text="1" Value="1">
                </asp:TreeNode>
                <asp:TreeNode Text="2" Value="2">
                    <asp:TreeNode Text="22" Value="22"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="3" Value="3"></asp:TreeNode>
                <asp:TreeNode Text="4" Value="4"></asp:TreeNode>
                <asp:TreeNode Text="5" Value="5">
                    <asp:TreeNode Text="55" Value="55"></asp:TreeNode>
                </asp:TreeNode>
            </Nodes>
            <ParentNodeStyle BackColor="Yellow" BorderColor="Red" BorderStyle="Dotted" BorderWidth="2px"
                ChildNodesPadding="3px" />
            <LevelStyles>
                <asp:TreeNodeStyle Font-Underline="False" />
                <asp:TreeNodeStyle Font-Underline="False" />
                <asp:TreeNodeStyle Font-Underline="False" />
                <asp:TreeNodeStyle Font-Underline="False" />
                <asp:TreeNodeStyle Font-Underline="False" />
            </LevelStyles>
            <SelectedNodeStyle BackColor="#FFC0C0" BorderColor="#FFFF80" BorderStyle="Solid"
                BorderWidth="1px" />
            <RootNodeStyle BackColor="#FFE0C0" BorderColor="Yellow" BorderStyle="Groove" BorderWidth="1px" />
        </asp:TreeView>