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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:05:26+00:00 2026-05-16T11:05:26+00:00

I generated an xml file like this: XElement employees = new XElement(Work, new XElement(record,

  • 0

I generated an xml file like this:

 XElement employees =
        new XElement("Work",
           new XElement("record",
              new XElement("Name", textBox1.Text),
              new XElement("Phone", "206-555-0144"),
              new XElement("Address",
                    new XElement("Street1", "123 Main St"),
                    new XElement("City", "Mercer Island"),
                    new XElement("State", "WA"),
                    new XElement("Postal", "68042")
             )),
             new XElement("record",
              new XElement("Name", "22222"),
              new XElement("Phone", "353245345"),
              new XElement("Address",
                    new XElement("Street1", "sdfain St"),
                    new XElement("City", "asdf Island"),
                    new XElement("State", "QLD"),
                    new XElement("Postal", "54322")
              )),
              new XElement("record",
              new XElement("Name", "Peter"),
              new XElement("Phone", "1234"),
              new XElement("Address",
                    new XElement("Street1", "sd St"),
                    new XElement("City", "cbr"),
                    new XElement("State", "act"),
                    new XElement("Postal", "2600")
              )
          )
      );

Later I wish to add new child node under parent node “record” based on a condition (where name=”peter”), something like this:

empFile.Elements().Where(r => (string)r.Element("Name") == "Peter")
                  .Add(new XElement("record",
                           new XElement("Mobile", "3253425"),
                           new XElement("Work", 999999)
                       ));

How can I achieve this?

  • 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-16T11:05:27+00:00Added an answer on May 16, 2026 at 11:05 am

    You are nearly there, your Where clause returns an IEnumerable<XElement> not a single XElement, so you just need to fix that, i.e. call .Single() or .First() etc

    eg:

    XElement xe = empFile.Elements().Where(r => (string)r.Element("Name") == "Peter").Single();
    
    xe.Add(new XElement("record", new XElement("Mobile", "3253425"), new XElement("Work", 999999)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML file that looks like this <Licence> <Name>Test company</Name> <Version>1.1.1.1</Version> <NumberOfServer>2</NumberOfServer>
I have an automatically generated XML file for the game that I run. It
How can I read mapping Xml file generated by Fluent NHibernate API?
I am trying to create an XML file to conform to someones XSD this
Let's say I have an empty XML file like so: <root></root> And I want
I need to generate an XML file in C#. I want to write the
I'm trying to generate customized xml files from a template xml file in python.
I have a T4 template that generates classes from an xml file. How can
Is there a tool to generate WiX XML given a .reg file? In 2.0,
I need to parse Visual Studio automatically generated XML documentation to create a report.

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.