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

  • Home
  • SEARCH
  • 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 738283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:49:07+00:00 2026-05-14T07:49:07+00:00

Trying to do a simple parse of an XML document. What’s the easiest way

  • 0

Trying to do a simple parse of an XML document. What’s the easiest way to pull out the two PropertyGroups below?

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     1
  </PropertyGroup>
  <PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2
  </PropertyGroup>
</Project>

I have been trying to use XElement.Elements(XName) but to do so I need to prefix PropertyGroup with the xmlns. The issue is that I don’t care about the name space and if it changes in future I would still like all PropertyGroups to be retrieved.

 var xml = XElement.Load(fileNameWithPath);
 var nameSpace = xml.GetDefaultNamespace();

 var propertyGroups= xml.Elements(nameSpace + "PropertyGroup");

Can you improve on this code such that I don’t need to prepend with nameSpace? I know I can essentially just reimplement the Elements method but I was hoping there was some way to pass a wildcard namespace?

Thanks,

Gavin

  • 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-14T07:49:08+00:00Added an answer on May 14, 2026 at 7:49 am

    Does this work for you?

    xml.Elements().Where(e => e.Name.LocalName == "PropertyGroup")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a simple string in C++. I know the string contains
The simple demo below captures what I am trying to do. In the real
I am trying to parse an XML response from a website in C#. The
I am trying something very simple, but for some reason it does not work.
I am trying to get simple jQuery to execute on my Content page with
I am trying to do simple tutorial in Visual Studio let someNumber = (2
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm just trying to do simple scripting with F#, and Math.PI seems to have
I'm writing an application and I'm trying to tie simple AJAX functionality in. It
Trying to find some simple SQL Server PIVOT examples. Most of the examples 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.