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 6909665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:43:04+00:00 2026-05-27T08:43:04+00:00

My XML is given below. <UrlRoutes> <ActivityPR> <Source>activity/editactivity</Source> <DestinationController>Activity</DestinationController> <DestinationAction>Editactivity</DestinationAction> </ActivityPR> <UserSettings> <Source>settings/subscriptions</Source> <DestinationController>UserSettings</DestinationController>

  • 0

My XML is given below.

<UrlRoutes>
  <ActivityPR>
     <Source>activity/editactivity</Source>
     <DestinationController>Activity</DestinationController>
     <DestinationAction>Editactivity</DestinationAction>  
  </ActivityPR>
  <UserSettings>
     <Source>settings/subscriptions</Source>
     <DestinationController>UserSettings</DestinationController>
     <DestinationAction>GetUserPreferenceSettings</DestinationAction>
  </UserSettings>
</UrlRoutes>

I will have Source element value in a var say sourceX . Ex

SourceX = "settings/subscriptions" 

or

SourceX = "activity/editactivity"

I am trying to get the parent node using the below code, let me know if there is something wrong

XmlElement xmlNode = xmlDoc.GetElementById(SourceX);
XmlNode parent = xmlNode.ParentNode;

Now for the combination for the parent node(say ActivityPR or Usersettings) and Source, I have to find the corresponding DestinationController and DestinationAction.

How do I do that? Prefer traditional XML as opposed to LINQ as rest of the code is in that form.

if(node!=null)
        {
            XmlElement routeElement = (XmlElement)node;


            strController = routeElement.GetElementsByTagName("DestinationController")[0].InnerText.ToString();
            strAction = routeElement.GetElementsByTagName("DestinationAction")[0].InnerText.ToString();


        }
  • 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-27T08:43:05+00:00Added an answer on May 27, 2026 at 8:43 am

    I’m assuming you’ve already loaded the XML into your XmlDocument – correct?

    In that case, you should be able to use something like this:

    string xpath = string.Format("/UrlRoutes/*[Source='{0}']", sourceX);
    XmlNode node = xmlDoc.SelectSingleNode(xpath);
    
    if(node != null)
    {
        // use the node to do whatever you need to do
    }
    

    The xpath expression basically selects any node under /UrlRoutes that contains a <Source> element with the given string as its value. This means: the values of <Source> need to be unique.

    Update: if you know you want to search only inside nodes <UserSettings>, you can make your XPath expression more selective:

    string parentNode = "UserSettings";
    string sourceX = "settings/subscriptions";
    
    string xpath = string.Format("/UrlRoutes/{0}[Source='{1}']", parentNode, sourceX);
    

    But with this more selective XPath, you would not be able to find a node when you have sourceX = "activity/editactivity" in your example (since that is not inside a <UserSettings> node)

    Update #2: I would probably use this code to grab the elements inside your node:

    if(node != null)
    {
       string dc = node.SelectSingleNode("DestinationController").InnerXml;
       string da = node.SelectSingleNode("DestinationAction").InnerXml;
    }
    

    That way, you don’t need to convert to an XmlElement first.

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

Sidebar

Related Questions

I have a xml given below: <root title=الصفحة الرئيسة> <item title=الصفحة الرئيسة itemuri=tcm:8-29-4 ShowInNav=True
I am looking to transform a input xml given below <profile name=default> <color id=forecolor
Given the XML below, I need to group by InputItem and sum the costs
I have the XML given below. From this XML, in an ASPX page with
I have part of XmlDocument Example.xml as given below: <rapaine dotoc=palin domap=rattmin> <derif meet=local
I have AJAX call to one XML file and the source code is given
Given below is my xml: <?xml version=1.0 encoding=utf-8?> <Report xmlns:rd=http://schemas.microsoft.com/SQLServer/reporting/reportdesigner xmlns=http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition> <Body> <ReportItems> <Textbox
I write code given below to read Atom feed. string strUrL = http://loluyede.blogspot.com/atom.xml; WebRequest
my build.XML is given below. <property name=src.dir value=src/> <property name=lib.dir value=lib/> <property name=build.dir value=build/>
I have got below given XML output: <?xml version=1.0?> <navigation path=/english> <resources> <Copyright>© 2009

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.