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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:12:04+00:00 2026-05-23T01:12:04+00:00

I have a snippet of an XML file that looks like: <?xml version=1.0 encoding=utf-16?>

  • 0

I have a snippet of an XML file that looks like:

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfCatalogItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <CatalogItem>
        <ID xmlns="http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices">bbe9b897-5d3b-4340-914b-fce8d6022bd9</ID>
        <Name xmlns="http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices">EmployeeReport</Name>
    </CatalogItem>

Now I’m trying to query the file for all the Name elements. I’m aware that I can use the SelectNodes("//Name") to give me what I want. However, since I have namespaces in the <ArrayOfCatalogItem> I have to account for that. So here’s the code I have so far:

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(@"C:\CatalogItems.xml");

// Create an XmlNamespaceManager for resolving namespaces
System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");

System.Xml.XmlNodeList nodeList;
System.Xml.XmlNode root = doc.DocumentElement;

nodeList = root.SelectNodes("//Name", nsmgr);
Console.WriteLine("There are {0} items.", nodeList.Count);
foreach (System.Xml.XmlNode item in nodeList)
{
    Console.WriteLine(item.InnerText);
}

However, the problem I’m having is the namespace definitions in the <Name> tag. How would I query the document for all Name values taking into account each <Name> has a namespace defined as an attribute?

  • 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-23T01:12:05+00:00Added an answer on May 23, 2026 at 1:12 am

    You’re using the wrong XML namespace – you need to use the one that is applied to the <Name> tag – not the document default namespaces (xsd: and xsi: prefixes).

    Try this:

    using System.Xml;
    
    XmlDocument doc = new XmlDocument();
    doc.Load(@"C:\CatalogItems.xml");
    
    // Create an XmlNamespaceManager for resolving namespaces
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("rs", "http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices");
    
    XmlNodeList nodeList;
    XmlNode root = doc.DocumentElement;
    
    nodeList = root.SelectNodes("//rs:Name", nsmgr);
    
    Console.WriteLine("There are {0} items.", nodeList.Count);
    
    foreach (XmlNode item in nodeList)
    {
        Console.WriteLine(item.InnerText);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file formatted like this: <?xml version=1.0 encoding=utf-8?> <Snippets> <Snippet name=abc>
I have a simple xml document that looks like the following snippet. I need
I have this xml snippet as part of a xml file that will be
I have defined a dp dimension in my XML file like so: <?xml version=1.0
I have a huge xml file that I would like to split up into
i have a snippet of xml that i've pasted in a text file which
I have an xml snippet that contains an object hierarchy: doc = \ <RootObj
I have an xml file which looked something like this... <RootElementTag> <ChildElementTag1 attribute1=value1 />
I have a XML file that I'm trying to group by the attribute Width.
IE doesn't like the å character in an XML file to display. Is that

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.