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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:25:35+00:00 2026-05-16T05:25:35+00:00

If I get the path to a specific node as a string can I

  • 0

If I get the path to a specific node as a string can I somehow easily find said node by using Linq/Method of the XElement ( or XDocument ).

There are so many different types of XML objects it would also be nice if as a added bonus you could point me to a guide on why/how to use different types.

EDIT: Ok after being pointed towards XPathSelectElement I’m trying it out so I can give him the right answer I can’t quite get it to work though. This is the XML I’m trying out

<Product>
  <Name>SomeName</Name>
  <Type>SomeType</Type>
  <Quantity>Alot</Quantity>
</Product>

and my code

string path = "Product/Name";
string name = xml.XPathSelectElement(path).Value;

note my string is coming from elsewhere so I guess it doesn’t have to be literal ( at least in debug mode it looks like the one above). I’ve also tried adding / in front. It gives me a null ref.

  • 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-16T05:25:36+00:00Added an answer on May 16, 2026 at 5:25 am

    Try using the XPathSelectElement extension method of XElement. You can pass the method an XPath expression to evaluate. For example:

    XElement myElement = rootElement.XPathSelectElement("//Book[@ISBN='22542']");
    

    Edit:

    In reply to your edit, check your XPath expression. If your document only contains that small snippet then /Product/Name will work as the leading slash performs a search from the root of the document:

    XElement element = document.XPathSelectElement("/Product/Name");
    

    If there are other products and <Product> is not the root node you’ll need to modify the XPath you’re using.

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

Sidebar

Related Questions

Having a method like this: @GET @Path(/name/{name}) @Produces(MediaType.TEXT_PLAIN) public String getProperty(@PathParam(name) String name) {
I wanted to ask if there is any way i can get path of
How can I get runnig path of my application from app.xaml.cs itself?
I am attempting to get full path of a selected node in the package
In Express under Node.js, I'd like to inspect a request under a specific path
How do I get specific path sections from a url? For example, I want
I'm trying to code a context-sensitive lexer rule using ANTLR but can't get it
Looking for a way to get path of file (and then process it in
How do I get the path of the current assembly? I need to get
How do I get the path of a an executed .jar file, in Java?

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.