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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:30:32+00:00 2026-06-01T11:30:32+00:00

I am looking to parse and modify a project file of type .dbproj .

  • 0

I am looking to parse and modify a project file of type .dbproj.

Sample XML

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    <ProjectGroup></ProjectGroup>
    <ItemGroup></ItemGroup>
    <ItemGroup></ItemGroup>
    <ItemGroup></ItemGroup>
    <ItemGroup>
      <Build Include="myfile.cs">
           <SubType>Code</SubType>
          </Build>
      <Build Include="myfile2.cs">
           <SubType>Code</SubType>
          </Build>
      <Build Include="myfile3.cs">
           <SubType>Code</SubType>
          </Build>
    </ItemGroup>
    <ItemGroup>
      <NotInBuild Include="myfile4.cs">
        <SubType>Code</SubType>
      </NotInBuild>
    </ItemGroup>
</Project>

I want to take the item from the 4th <ItemGroup> with the attribute Include="myfile.cs" and remove it from said <ItemGroup>. Next, I want to add this element:

<NotInBuild Include="myfile.cs">
    <SubType>Code</SubType>
</NotInBuild>

It is slightly modified from the one removed to the 5th ItemGroup. The result should be:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    <ProjectGroup></ProjectGroup>
    <ItemGroup></ItemGroup>
    <ItemGroup></ItemGroup>
    <ItemGroup></ItemGroup>
    <ItemGroup>
      <Build Include="myfile2.cs">
           <SubType>Code</SubType>
          </Build>
      <Build Include="myfile3.cs">
           <SubType>Code</SubType>
          </Build>
    </ItemGroup>
    <ItemGroup>
      <NotInBuild Include="myfile.cs">
        <SubType>Code</SubType>
      </NotInBuild>
      <NotInBuild Include="myfile4.cs">
        <SubType>Code</SubType>
      </NotInBuild>
    </ItemGroup>
</Project>

Per another SO post by Skeet, I started going down the LINQ path.I don’t know where to go from here

XDocument doc = XDocument.Load(XmlDocumentPath);
XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
                var query = doc.Root          
                .Elements(ns + "ItemGroup");
  • 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-01T11:30:34+00:00Added an answer on June 1, 2026 at 11:30 am

    Using this collection class and the associated extensions: http://searisen.com/xmllib/xelementcollection.wiki

    And these classes:

    public class Project
    {
        XElement self;
        public Project(FileInfo file)
        {
            self = XElement.Load(file.FullName);
        }
    
        public ItemGroup[] ItemGroup
        {
            get
            {
                return _ItemGroup
                    ?? (_ItemGroup = self.GetEnumerable("ItemGroup", x => new ItemGroup(x)).ToArray());
            }
        }
        ItemGroup[] _ItemGroup;
    }
    
    public class ItemGroup
    {
        XElement self;
        public ItemGroup(XElement self)
        {
            this.self = self;
        }
    
        public XElementCollection Build
        {
            get
            {
                return _Build
                    ?? (_Build = new XElementCollection(self, "Build",
                             (a, b) => a.Get("Include", string.Empty) ==
                                       b.Get("Include", string.Empty),
                             false));
            }
        }
        XElementCollection _Build;
    
        public XElementCollection NotInBuild
        {
            get
            {
                return _NotInBuild
                    ?? (_NotInBuild = new XElementCollection(self, "NotInBuild",
                             (a, b) => a.Get("Include", string.Empty) ==
                                       b.Get("Include", string.Empty),
                             false));
            }
        }
        XElementCollection _NotInBuild;
    }
    

    Then this sort of messy implementation:

    Project project = new Project(xmlFile2);
    XElement find = null;
    ItemGroup item = project.ItemGroup.FirstOrDefault(i =>
        (find = i.Build.Find(x => x.Get("Include", string.Empty) == "myfile.cs")) != null);
    if (null != find)
    {
        XElement not = new XElement(find.Name.Namespace + "NotInBuild");
        not.Set("Include", "myfile.cs", true);
        foreach (var child in find.Elements().ToArray())
            not.Add(child);
        find.Remove();
        ItemGroup notGroup = project.ItemGroup.FirstOrDefault(i => i.NotInBuild.Count > 0);
        notGroup.NotInBuild.Add(not);
    }
    

    Using the extension methods mentioned at the top, the namespace issue is a non-issue.

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

Sidebar

Related Questions

Looking to parse the following text file: Sample text file: <2008-10-07>text entered by user<Ted
I'm looking for a way to parse an xml/html document in ruby, which contains
We're looking for a way to parse large amounts of XML files that conform
I am looking to parse XML data (using this URL: https://gdata.youtube.com/feeds/api/videos/ijudAdhLGmg?v=2 ) and get
I'm looking for a way to parse XML in C++ in Windows and I've
I am looking for a PHP class that can parse an ICalendar (ICS) file
I am currently looking to process and parse out information from this .txt file
I'm looking for the best way to parse XML on iOS. There seem to
I am looking for a way to parse a text file I have into
I'm looking to parse some CXML in PHP...basically all I'm looking to get the

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.