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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:19:58+00:00 2026-06-12T06:19:58+00:00

I got this answer to a question i asked yesterday about how to use

  • 0

I got this answer to a question i asked yesterday about how to use a path to access an element-

Is it possible to do the opposite? means if i locate a specifiec element(level4 in the xml) with
GetElementsByTagName method is there a way to get the path for this elements and assign it
to a variable for later use?

<?xml version="1.0" encoding="utf-8" ?>
<level1> 
    <level2> 
        <level3>header3</level3> 
            <level4>header4</level4> 
        <level3>header31</level3> 
    </level2> 
    <level2> 
        <level3>nnn</level3> 
        <level3>nnnnn</level3> 
    </level2> 
</level1> 
  • 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-06-12T06:20:00+00:00Added an answer on June 12, 2026 at 6:20 am

    Suppose you have extracted your node by

    XmlNodeList nl = doc.GetElementsByTagName("level4");

    then

            XmlNode node = nl[0]; 
            String sPath = node.Name;
            System.Xml.XmlNode np = node.ParentNode;
            while (np != null && np.NodeType != XmlNodeType.Document)
            {
                sPath = String.Format("{0}/{1}", np.Name, sPath);
                np = np.ParentNode;
            }
            sPath = "/" + sPath;
            Debug.WriteLine(sPath);
    

    and you get “/level1/level2/level4” as the value of sPath

    *Note: this in correct because in the input XML level3 is Sibling of level4 ( not Parent )

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

Sidebar

Related Questions

I asked this question yesterday got a pretty good answer but can't figure out
Yesterday, I asked this question and never really got an answer I was really
I asked this question before and got a great working answer. what is the
I asked this question on the SCB forum but got no answer I'm trying
I asked this question (below) a week ago and got the answer I was
I had asked this question before, but I got no correct answer. So, this
yesterday i asked one question and got the answer from our friend here, and
Ok, I asked this question and got excellent code example as answer. The code
I asked a question yesterday and the answer I got has answered the first
I've asked this question yesterday and got lots of good answers, only I just

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.