Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 200725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:08:12+00:00 2026-05-11T17:08:12+00:00

I have a recusive-method that creates a unordered list from a XML document. To

  • 0

I have a recusive-method that creates a unordered list from a XML document. To check which node I am positioned on I use the querystring to match the URL in the XML document.

I need to add the class ‘current’ on the parent node if I am positioned on its child node.

Like this:

    MenuItem 1
    MenuItem 2 [class current]
         MenuItem 3 [class current] (selected node)
    MenuItem 4

My XML document is like this:

<MenuItem Name="MenuItem 1" Url="MenuItem1.aspx"/>
<MenuItem Name="MenuItem 2" Url="MenuItem2.aspx">
    <MenuItem Name="MenuItem 3" Url="MenuItem3.aspx" />
</MenuItem>
<MenuItem Name="MenuItem4" Url="MenuItem4.asp" />

And my current code looks like this:

foreach (XmlNode item in menuitems)
{
    if (HttpContext.Current.Request.Url.AbsolutePath.ToLower() == item.Attributes["Url"].Value.ToLower())
    {
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "current");
    }
    writer.RenderBeginTag(HtmlTextWriterTag.Li);
    // And so on...
}

So I need some kind of function to find this node and place a class on that node aswell.

If you need more code, information or anything else – please say so! 🙂

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:08:12+00:00Added an answer on May 11, 2026 at 5:08 pm

    Thanks for the answers. But I solved my own problem. You guys get upvotes for your effort.

    Here was my solution:

    System.Collections.Hashtable ht = new System.Collections.Hashtable();
    ht.Add("Url", HttpContext.Current.Request.Url.AbsolutePath.ToLower());
    
    XmlNode currentpage = Core.FindChildNode(item, "MenuItem", ht);
    
    if (HttpContext.Current.Request.RawUrl.ToLower() == item.Attributes["Url"].Value.ToLower() || currentpage != null)
    {
         writer.AddAttribute(HtmlTextWriterAttribute.Class, "current");
    }
    

    This is my FindChildNode method

    public static XmlNode FindChildNode(XmlNode parent, string name, System.Collections.Hashtable keyvaluecollection)
        {
            if (parent.NodeType != XmlNodeType.Element) return null;
            XmlElement el = (XmlElement)parent;
    
            XmlNodeList nodes = el.GetElementsByTagName(name);
            foreach (XmlNode node in nodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    bool found = false;
                    foreach (string key in keyvaluecollection.Keys)
                    {
                        if (node.Attributes[key] != null && node.Attributes[key].Value == (string)keyvaluecollection[key])
                        {
                            found = true;
                        }
                        else
                        {
                            found = false;
                            break;
                        }
                    }
                    if (found) return node;
                }
            }
            return null;
        }
    

    Seems to work like a charm! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd say that installing mercurial and using tortoisehg has been… May 11, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer It's hard to make useful one-liner filters in Python. You… May 11, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer Stick with ISO8601 and you can't go wrong. Preferably, YYYYMMDD… May 11, 2026 at 10:30 pm

Related Questions

Greetings, I'm looking for a method to do in-line result (output) document selecting in
I've created a copy utility in c# (.NET 2.0 Framework) that copies files, directories
My folder Structure /UNIX /Find /Grep /Find-Grep I made a symlink to the UNIX
I have recently written a dynamic querying tool using expression trees and as I
I'm looking to make a recursive method iterative. I have a list of Objects

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.