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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:43:10+00:00 2026-06-14T07:43:10+00:00

I am trying to parse a vcxproj file, using – any method I can

  • 0

I am trying to parse a vcxproj file, using – any method I can (I have tried XPathDocument, XElement, XDocument… nothing works)

The typical project configuration:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="P">  ...  </ItemGroup>
  <ItemGroup>   <C I="..." />    </ItemGroup>
  <ItemGroup>   <C I="..." />    </ItemGroup>
  <ItemGroup>    ...  </ItemGroup>    
  <Import Project="aaaaa" />
  <PropertyGroup C="..." Label="...">  ... </PropertyGroup>  
  <Import Project="ooother" />
  <ImportGroup Label="E">  </ImportGroup>
  <ImportGroup Label="I_NEED_THIS" C="...">
    <Import Project="other" Condition="x" Label="L" />
    <Import Project="I_NEED_THIS_VALUE" />
  </ImportGroup>  
  <Import Project="bbbbb" />
  <ImportGroup Label="Ex">  </ImportGroup>
</Project>

I am trying to get the item(s) from inside the ImportGroup with the Label I_NEED_THIS, I would like to get all of them and be able to check (if they have) their Label, or Condition…

I suspected that the problem may be that there are multiple elements with similar names, so I tried to just get one level at a time,

XElement xmlTree = XElement.Load(projectPath);
XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
List<XElement> projectElements = (
    from mainElement in xmlTree.Descendants(ns + "Project")
    from subElement in mainElement.Elements()
    select subElement
).ToList();

if (projectElements.Count == 0)
  MessageBox.Show("Nothing is working today");

The above, to be followed with a few foreach loops…

foreach (XElement projectElement in projectElements)
{
List<XElement> importElements = (
   from mainElement in projectElement.Descendants(ns + "ImportGroup")
   from subElement in mainElement.Elements()
   select subElement
).ToList();
...
}

And so on, but when testing even the first loop, the Count of the projectElements was 0…

I have tried it without the namespace as well…

What am I missing ?
Thank you…

  • 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-14T07:43:11+00:00Added an answer on June 14, 2026 at 7:43 am

    You can get rid of those calls to Descendants. Calling Elements directly should be fine. This is how to achieve this using simple loops:

    // we can directly grab the namespace, it's better than hard-coding it
    XNamespace ns = xmlTree.Name.Namespace;
    // xmlTree itself is the Project element, just to make sure:
    Debug.Assert(xmlTree.Name.LocalName == "Project");
    
    // the following is all elements named "ImportGroup" under "Project"
    var importGroups = xmlTree.Elements(ns + "ImportGroup");
    foreach(XElement child in importGroups)
    {
        // the following are all "Import" elements under "ImportGroup" elements
        var imports = child.Elements(ns + "Import");
        foreach (var importElem in imports)
        {
            Console.WriteLine(importElem.Attribute("Project").Value);
        }
    }
    
    //This is the output:
    //other
    //I_NEED_THIS_VALUE
    

    Alternatively you can use the following code, which directly goes to the second element that contains the attribute valued "I_NEED_THIS_VALUE":

    var elems = xmlTree.Elements(ns + "ImportGroup")
        .Where(x => x.Attributes("Label").Any(xattr => xattr.Value == "I_NEED_THIS"))
            .Elements(ns + "Import")
            .Where(x => x.Attributes("Project").Any(xattr => xattr.Value == "I_NEED_THIS_VALUE"));
    
    • 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 an INI file using C++. Any tips on what is
Trying to parse Maplines for an airport. Each airport can have X number of
I'm trying to parse a file from the web on Android using the DOM
Trying to parse and XLSX file using roo gem in a ruby script. In
Whilst trying to parse MS Excel file using POI-HSSF v3.2 I am getting IndexOutOfBoundsException.
Trying to parse the following Python file using the lxml.etree.iterparse function. sampleoutput.xml <item> <title>Item
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>
Trying to parse an HTML document and extract some elements (any links to text
Im trying to parse the string located in /proc/stat in a linux filesystem using
I'm trying to parse a CSV file in C#. Split on commas (,). I

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.