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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:16:21+00:00 2026-06-11T06:16:21+00:00

I have a simple xml, I created a XmlDocument out of it and used

  • 0

I have a simple xml, I created a XmlDocument out of it and used Xpath to fetch a node, I need to pass this node to other parts of the code where I may use further xpath functions on the XmlNode object to get other sub nodes. But in the code below

string xmlString = "<catalog><music><cds><cd><title>First Title</title><author>Author    1</author></cd><cd><title>Second Title</title><author>Author 2</author></cd></cds></music></catalog>";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlString);
XmlNode musicNode = xmlDocument.SelectSingleNode("/catalog/music");
XmlNode cdsNode = musicNode.SelectSingleNode("/cds");

when I print the name of the musicNode, I am getting “music”, so I assume that I have the “music” node. So I again applied xpath expression “/cds” on the music node assuming I would get the “cds” XmlNode, but cdsNode in the code returns undefined value, but if I do

XmlNode cdsNode = musicNode.SelectSingleNode("/catalog/music");

I am getting a valid value for cdsNode that is the “music” node again, I suppose musicNode represents the XmlDocument instead of the “music” XmlNode??? Am I missing something, I am from Java and in Java navigating to subnodes from Node is possible using xpath, like an xpath expression “/cds” on the musicNode would have returned a valid cdNode

  • 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-11T06:16:23+00:00Added an answer on June 11, 2026 at 6:16 am

    / will always go back to the root of the underlying XmlDocument, irrespective of the current node.

    Drop the / and navigate a relative path, and you should be good, i.e.

    XmlNode musicNode = xmlDocument.SelectSingleNode("/catalog/music");
    XmlNode cdsNode = musicNode.SelectSingleNode("cds");
    

    or just walk the whole path again

    XmlNode cdsNode = xmlDocument.SelectSingleNode("/catalog/music/cds");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple screen created in xml, the parent layout is a relativelayout
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have a simple c++ Application. This Application is just printing text out. I
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php
I have a simple xml of users. I have a StudentId , I just
I have really simple XML (HTML) parsing ANTLR grammar: wiki: ggg+; ggg: tag |
I have a simple XML extraction issue that should be solvable with straight PHP
i have a simple xml file in a wcf service that i am trying
I have a simple xml file and I want to remove everything before the
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>

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.