locked
A good way to read from custom xml sitemap RRS feed

  • Question

  • User425811032 posted

    Hello

    I have tried tinkering with xml functions and I am unable to get the result of what I am after, the thing is that I need to populate a repeater control (essentially a menu) from a filtered datatable from the xml parameters for each siteMapNode.
    Then from the datatable with filtered results populate the repeater control.

    My sitemap is has the following xml: (I know having multiple siteMapNode's is not valid, but this is a custom sitemap)

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap>
      <siteMapNode title="Welcome" description="Welcome Screen / Landing Page"
              type="intro">
        <siteMapNode title="About Us"
               description="What/Who are We"
               url="~/About.aspx" />
        <siteMapNode title="Contact Us"
               description="Contact Form"
               url="~/Contact.aspx" />
      </siteMapNode>
      <siteMapNode title="Thing Participant" description="A Thing is normally chosen to be here"
              type="Thing" url="~/Thing.aspx">
        <siteMapNode title="Thing Details"
               description="Training"
               url="#Details" />
        <siteMapNode title="Score"
               description="See scores"
               url="#Scoreboard" />
        <siteMapNode title="Team Management"
               description="View Team"
               url="#Management" />
      </siteMapNode>
      <siteMapNode title="Organizer" description="Organize Things"
              type="organizer" roles="organizer" url="~/ThingOrganizer.aspx">
        <siteMapNode title="My Things"
               description="Shows Things you are assigned"
               url="#MyThings" />
      </siteMapNode>
      <siteMapNode title="Admin" description="Create Thing/Edit Things"
              type="admin" roles="admin" url="~/ThingAdmin.aspx">
        <siteMapNode title="Create Thing"
               description="Training"
               url="#New" />
        <siteMapNode title="View Things"
               description="Views Things in system, able to edit them"
               url="#Edit" />
      </siteMapNode>
      <siteMapNode title="System/Debug" description="System Debug Info"
            type="admin" roles="admin" url="~/System.aspx"></siteMapNode>
    </siteMap>

    What I want is from my Master(template), read each node from the top, find my current URL(HttpContext.Current.Request.Url.AbsolutePath) and see what nodes it has a url attribute matching the current url - notes with url like #MyThings, should read the parent nodes url, so the url would be "~/ThingOrganizer.aspx#MyThings".
    If not url is given then menu will not be displayed as a menu item, menu is single level.
    futhermore roles will check if the user has the correct role with example Roles.IsUserInRole(User.Identity.Name, "admin").
    A picture says a thousand words - here is two examples:

    explained

    Orange(object►siteMap►siteMapNode►0►siteMapNode):Will only show menus from here, if the current url path is either: ~/Contact.aspx || ~/About.aspx
    if the parent of the tree where the site is does not have an url then it will now show it as a menu item.
    Yellow(object►siteMap►siteMapNode►3►siteMapNode): Will only show menus from here, if the current url path is: ~/ThingAdmin.aspx (ThingAdmin.aspx#New || ThingAdmin.aspx#Edit)
    if the parent of the tree where the site is does not have an url then it will use it for urls that are not true urls, ex: #ToShowANewView

    So current page sees where its path is shown inside the sitemap and then reads the appropriate menu items.

    - Do you guys have a good idea to make this work?

    Wednesday, May 16, 2018 10:25 PM

All replies

  • User283571144 posted

    Hi zassadgh,

    According to your description, I couldn't understand your requirement clearly.

    Do you mean you want to generate the Hyperlink element according to the xml site map?

    Do you mean you want to filter the site map url into four categories?

    If the url insider the category, it will show all the other url insider category.

    Best Regards,

    Brando

    Thursday, May 17, 2018 1:46 PM
  • User425811032 posted

    "If the url insider the category, it will show all the other url insider category." - Yes, tried illustrate that in the image.

    The problem is to:
    1: iterate through the xml nodes and find the node that has the current visited url
    2: get the above siteMapNode for the node that has the containing current visited url (single level menu) - tried to illustrate it with the image with 2 examples.
    3: filter if current user does not have role, if role required or if it does not have a url, then it will take the immidate siteMapNode under siteMap and use its url attribute, for example siteMapNode [2], I visit example.com/ThingAdmin.aspx then I would have 3 entrys in my datatable total as displayed in yellow frame image.
    4: use the populated datatable that will be used for a repeater to generate menu items.

    What I need to find out first is the best way to search for notes and go back and forth to see what information is required, example if url attribute is a #NotTrueLink, then it will get the immidate siteMapNode under siteMap url parameter and be like "~/Example.aspx#NotTrueLink".
    I can try and explain it with some more in depth scenarios.

    But a good starting point for me would be how to easily iterate though it, find the immidate siteMapNode under siteMap where the current url is(url attribute match HttpContext.Current.Request.Url.AbsolutePath), then how to go through all below nodes of the immidate siteMapNode, as these should populate a datatable(where I can filter with if statements), and mostly get the immidate siteMapNode under siteMap url attribute if the url of the node below is not a true url, but like: #NotTrueLink, then it will take the immidate siteMapNode under siteMap url attribute and make the link "~/Example.aspx#NotTrueLink", if the immidate siteMapNode under siteMap url attribute is "~/Example.aspx", and the siteMapNode under it has url attribute #NotTrueLink".

    Thursday, May 17, 2018 3:52 PM
  • User425811032 posted

    I modified my requirements as it is not possible to get fragments.
    Currently sitemap syntax is:

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap>
      <siteMapNode title="Intro" description="Introduction to us" type="intro">
        <siteMapNode title="Welcome" description="Landing Page" url="/Default.aspx" />
        <siteMapNode title="About Us" description="What/Who are We" url="/About.aspx" />
        <siteMapNode title="Contact Us" description="Contact Form" url="/Contact.aspx" />
      </siteMapNode>
      <siteMapNode title="Event Participation" description="A Event is normally chosen to be here" type="event" retainParameter="true">
        <siteMapNode title="Event Details" description="Training" url="/Event.aspx" retainParameter="true"/>
        <siteMapNode title="Scoreboard" description="See top scores" url="/Scoreboard.aspx" retainParameter="true"/>
        <siteMapNode title="Team Management" description="Create Team/Join Team/View Team" url="/EventTeam.aspx" retainParameter="true"/>
        <siteMapNode title="Participate" description="Interface with out Smart Beerbong and Participate" url="/EventParticipate.aspx" retainParameter="true"/>
      </siteMapNode>
      <siteMapNode title="Event Organizer" description="Organize Events" type="organizer" roles="organizer">
        <siteMapNode title="My Events" description="Shows Events you are assigned" url="/Organizer/EventOrganizer.aspx" />
        <siteMapNode title="Edit Events" description="Edit selected event" url="/Organizer/EventOrganizer.aspx" retainParameter="true" hide="true"/>
      </siteMapNode>
      <siteMapNode title="Admin" description="Administrator for Platform" type="admin" roles="admin">
        <siteMapNode title="User Management" description="Manage Users" url="/Admin/UserManagement.aspx" />
        <siteMapNode title="Event Management" description="Manage Events" url="/Admin/EventManagement.aspx" />
      </siteMapNode>
      <siteMapNode title="System/Debug" description="System Debug Info" type="admin" roles="admin">
        <siteMapNode title="Event Management" description="Manage Events" url="/Admin/Info.aspx" />
      </siteMapNode>
    </siteMap>

    First I am trying to get all pages that has to do with roles for a secondary menu:

    /siteMap//*[@roles='admin']


    The problem is I get an output like this:

    <siteMapNode title="Contact Us" roles="admin" description="Contact Form" url="/Contact.aspx" /><siteMapNode title="Admin" description="Administrator for Platform" type="admin" roles="admin">
      <siteMapNode title="User Management" description="Manage Users" url="/Admin/UserManagement.aspx" />
      <siteMapNode title="Event Management" description="Manage Events" url="/Admin/EventManagement.aspx" />
    </siteMapNode><siteMapNode title="System/Debug" description="System Debug Info" type="admin" roles="admin">
      <siteMapNode title="Event Management" description="Manage Events" roles="admin" url="/Admin/Info.aspx" />
    </siteMapNode><siteMapNode title="Event Management" description="Manage Events" roles="admin" url="/Admin/Info.aspx" />


    but looking for a return where the role is inherit if it is not specified inside the immidate parent.

    <siteMapNode title="Contact Us" roles="admin" description="Contact Form" url="/Contact.aspx" /><siteMapNode title="Admin" description="Administrator for Platform" type="admin" roles="admin">
      <siteMapNode title="User Management" description="Manage Users" url="/Admin/UserManagement.aspx" />
      <siteMapNode title="Event Management" description="Manage Events" url="/Admin/EventManagement.aspx" />
    </siteMapNode><siteMapNode title="System/Debug" description="System Debug Info" type="admin" roles="admin">


    Is there a way take inherting into consideration from my above xpath?

    Monday, May 21, 2018 8:48 AM
  • User283571144 posted

    Hi zassadgh,

    According to your sitemap syntax, I couldn't find the Contact Form xml node contains the roles attribute.

    Could you please post more details xml codes about your xml file and your test codes?

    If you could post more details information, it will be more easily for us to reproduce your issue and find the solution.

    Best Regards,

    Brando

    Monday, May 28, 2018 6:48 AM