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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:27:20+00:00 2026-06-15T07:27:20+00:00

<root> <element1>innertext</element1> <element2>innertext</element2> <element3> <child1>innertext</child1> </element3> </root> I have an xml structure shown above.

  • 0
<root>
    <element1>innertext</element1>
    <element2>innertext</element2>
    <element3>
        <child1>innertext</child1>
    </element3>
</root>

I have an xml structure shown above.

I would like to “append” the xml file (it is already created) to add another “child” inside element3>, so that it will look like this:

<root>
    <element1>innertext</element1>
    <element2>innertext</element2>
    <element3>
        <child1>innertext</child1>
        <child2>innertext</child2>
    </element3>
</root>

Linq to xml and/or Xpath would be great

EDIT:
I have tried doing this:

XElement doc = XElement.Load(mainDirectory);
XElement newElem = doc.Elements("element3").First();
newElem.Add(new XElement("child2", "child2innertext"));
doc.Add(newElem);
doc.Save(mainDirectory); 
  • 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-15T07:27:22+00:00Added an answer on June 15, 2026 at 7:27 am

    With XDocument you can achieve this as:

     string xml = "<root><element1>innertext</element1><element2>innertext</element2><element3><child1>innertext</child1></element3></root>";
    
     var doc = XDocument.Parse(xml); //use XDocument.Load("filepath"); in case if your xml is in a file.
    
     var el3 = doc.Descendants("element3").FirstOrDefault();
    
     el3.Add(new XElement("child2", "innertext"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml that comes in two forms <root> <element1 req=mandatory/> <element2/> <element3/>
I have an XML File resembling the following: <root> <parent label=parent1> <child label=child1> <element1>data</element1>
I have a sample.xml file like this: 'root element 'FilePath element 'FilePath element value
<root> <data1> <Element1>Value</Element1> <Element2>Value</Element2> <Element3>Value</Element3> </data1> <data2> <Element1>Value</Element1> <Element2>Value</Element2> </data2> </root> From the above
I have the following xml: <root> <Element1> <Hierarchy attr=value/> <Hierarchy attr=value/> <Hierarchy attr=value/> <Hierarchy
I have an xml file with following structure: <table name=tblcats> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId>
I have a snippet of an XML file that looks like: <?xml version=1.0 encoding=utf-16?>
How do I define schema for the following XML: <root> <elements> <element1/> <element2/> <element1/>
my problem is like this. Let's say i have xml like this <root> <child
I have an XML document with following structure: root element DataModel can have children

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.