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

  • SEARCH
  • Home
  • 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 8541921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:56:24+00:00 2026-06-11T11:56:24+00:00

I am trying to pull out data from an XML document that seems to

  • 0

I am trying to pull out data from an XML document that seems to use relative references like this:

<action>
  <topic reference="../../action[110]/topic"/>
  <context reference="../../../../../../../../../../../../../contexts/items/context[2]"/>
</action>

Two questions:

  1. Is this normal or common?
  2. Is there a way to handle this with linq to XML / XDocument or would I need to manually traverse the document tree?

Edit:

To clarify, the references are to other nodes within the same XML document. The context node above references a list of contexts, and says to get the one at index 2.

The topic node worries me more because it’s referencing a certain other action’s topic, which could in turn reference a list of topics. If that wasn’t happening I would have just loaded the lists of contexts and topics in a cache and looked them up that way.

  • 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-11T11:56:25+00:00Added an answer on June 11, 2026 at 11:56 am

    I ended up manually traversing the tree. But with extension methods it’s all nice and out of the way. In case it might help anyone in the future, this is what I threw together for my use-case:

    public static XElement GetRelativeNode(this XAttribute attribute)
        {
            return attribute.Parent.GetRelativeNode(attribute.Value);
        }
    
        public static string GetRelativeNode(this XElement node, string pathReference)
        {
            if (!pathReference.Contains("..")) return node; // Not relative reference
    
            var parts = pathReference.Split(new string[] { "/"}, StringSplitOptions.RemoveEmptyEntries);
            XElement current = node;
            foreach (var part in parts)
            {
                if (string.IsNullOrEmpty(part)) continue;
                if (part == "..")
                {
                    current = current.Parent;
                } 
                else
                {
                    if (part.Contains("["))
                    {
                        var opening = part.IndexOf("[");
                        var targetNodeName = part.Substring(0, opening);
                        var ending = part.IndexOf("]");
                        var nodeIndex = int.Parse(part.Substring(opening + 1, ending - opening - 1));
    
                        current = current.Descendants(targetNodeName).Skip(nodeIndex-1).First();
                    } 
                    else
                    {
                        current = current.Element(part);    
                    }
    
                }
            }
    
            return current;
        }
    

    And then you’d use it like this (item is an XElement):

    item.Element("topic").Attribute("reference").GetRelativeNode().Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pull out data from the table I had from the
I am trying to parse some XML that looks similar to this: <document> <headings>
I'm trying to pull out specific elements from results from the Data Science Toolkit
I'm trying to pull some data out of an OLD database that is running
I'm trying to pull some data out of logs on remote machines using awk,
I'm trying to pull a large amount of data out of a WCF web
I'm trying to pull out a list of table names from a MySQL database.
im having some difficulty trying to pull out a specific value from a cookie.
I'm trying to complete a regular expression that will pull out matches based on
I am trying to pull data from a table I have imported into my

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.