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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:26:44+00:00 2026-05-31T05:26:44+00:00

Given an XElement loaded with var root = XElement.Load(foo.xml); How can you enumerate the

  • 0

Given an XElement loaded with

var root = XElement.Load("foo.xml");

How can you enumerate the namespaces used in the XML file?

  • 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-31T05:26:45+00:00Added an answer on May 31, 2026 at 5:26 am

    There is nothing that gives you all the namespaces used directly, so you have to enumerate all elements and extract their namespaces:

    var namespaces = root.DescendantsAndSelf()
                         .Select(e => e.Name.Namespace)
                         .Distinct();
    

    This would give you only the namespaces that were used by elements in the document. If you want to list all namespaces that are declared in the document (even if they are not used or if they are used only by attributes), you would need to iterate the namespace declarations:

    var namespaces = root.DescendantsAndSelf()
                         .Attributes()
                         .Where(a => a.IsNamespaceDeclaration)
                         .Select(a => (XNamespace)a.Value)
                         .Distinct();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given the following XML structure: <courses> <course> <title>foo</title> <description>bar</description> </course> ... </courses> How could
Given this XML, how can I retrive the HEX color? <group> <span style=color:#DF0000; font-style:
Given the following XML file: <users> <user name=admin password=foobar roles=Admin,Guest /> <user name=guest password=foobar
Given a file path (e.g. /src/com/mot ), how can I check whether mot exists,
Given the following Xml fragment: <root> <sheetData> <row r=1 /> <row r=2 /> <row
http://www.dreamincode.net/forums/xml.php?showuser=335389 Given the XML above, how can I iterate through each element inside of
I am using an XML file to store the values. This XML file can
I've got an XElement deep within a document. Given the XElement (and XDocument?), is
Given a (source) patch file, what's the easiest way to apply this patch on

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.