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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:42:25+00:00 2026-06-17T09:42:25+00:00

The structure of the XML file is more or less as follows: <?xml version=1.0

  • 0

The structure of the XML file is more or less as follows:

<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="url1" xsi:schemaLocation="url2 url3">
   <b>
     <c></c>
     <c></c>
     <c></c>
   </b>
</a>

My goal is to select all the “c” elements, but the following xpath expression won’t work: “//a/b/c”.

ie:

XmlDocument doc= new XmlDocument();
doc.Load(filepath);
XmlNodeList l = doc.SelectNodes("//a/b/c"); // 0 nodes

The only xpath expressions I tested that worked are /* (1 node) and //* (all nodes).

Is this problem related to the XML namespace? If so, what’s the proper way to set up the XMLDocument object?

        XmlDocument doc= new XmlDocument();
        doc.Load(filepath);
        XmlNamespaceManager m = new XmlNamespaceManager(doc.NameTable);
        m.AddNamespace(/* what goes here? */);
        XmlNodeList l = doc.SelectNodes("//a/b/c", m);
  • 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-17T09:42:26+00:00Added an answer on June 17, 2026 at 9:42 am

    You need to assign a namespace prefix for the default namespace that the document is using, and then use that in your XPath:

    XmlDocument doc= new XmlDocument();
    doc.Load(filepath);
    
    XmlNamespaceManager m = new XmlNamespaceManager(doc.NameTable);
    m.AddNamespace("myns", "url1");
    
    XmlNodeList l = doc.SelectNodes("/myns:a/myns:b/myns:c", m);
    

    You can replace the prefix “myns” with essentially anything (alphanumeric without spaces), as long as it’s consistent between line 4 and the XPath, and that it’s correctly assigned to the “url1” namespace in line 4.

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

Sidebar

Related Questions

consider my 'destinationURLLookUp.xml' file has the following structure <?xml version=1.0 encoding=UTF-8?> <destinationURLs xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <destinationURL
I'm reading an XML file that looks like this: <?xml version=1.0 encoding=utf-8?> <VehicleList> <Vehicle>
I have an XML document that contains the following structure: Its more or less
I have constructed an XML tree structure of an XML file. I am able
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...
I have an xml file with the following structure: <main_tag> <first> <tag1>val1</tag1> <conf> <tag2>val2</tag2>
I have an XML file format that contains a structure of questions: <question id=q101>
I have an xml file that contains a structure.. In this structure, I have
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
I have to parse a 1Gb XML file with a structure such as below

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.