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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:24:47+00:00 2026-06-09T01:24:47+00:00

I have two XML documents. My objective is to replace one of the nodes

  • 0

I have two XML documents.
My objective is to replace one of the nodes in the first document with the entire contents of the second Xml documents.
So the first document – Parent looks something like this:

<Root>
    <AgencyName = "Some Agency"/>
    <Originator = "Some other Agency"/>
    <Type = "AnonymousType"/>
    <Details/>
</Root>

The second document – children looks like this:

<Root>
    <Details>
        <Detail1>
            ...
        </Detail1>
        <Detail2>
            ...
        </Detail2>
        <Detail3>
            ...
        </Detail3>
    </Details>
</Root>

The node <Details/> has to be replaced with the contents of the second document.
I am attempting to use Linq to XML to do this. The first document is represented in an XDocument class and the second one is represented in an XElement class. There are several child attributes for <Detail/> and I haven’t listed them here.

I am attempting to replace the element from the first document with this XElement class.
If I try something like this,

ParentDoc.Element("Details").ReplaceAll(children);

it is unlikely to work. How should I do the replace?

  • 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-09T01:24:49+00:00Added an answer on June 9, 2026 at 1:24 am
    var doc = XDocument.Load(@"C:\Tools\test.xml");
    var doc2 = XDocument.Load(@"C:\Tools\test2.xml");
    var children = doc2.Root.Element("Details");
    var parentNode = doc.Root.Element("Details");
    parentNode.ReplaceWith(children);
    

    By the way, your xml are not correct, so you’ll get exceptions.

    I tried with

    <Root>
        <AgencyName name= "Some Agency"/>
        <Originator name= "Some other Agency"/>
        <Type name= "AnonymousType"/>
        <Details/>
    </Root>
    

    and

    <Root>
        <Details>
            <Detail1>
               asdf
            </Detail1>
            <Detail2>
                asde
            </Detail2>
            <Detail3>
                eere
            </Detail3>
        </Details>
    </Root>
    

    and got

    <?xml version="1.0" encoding="utf-8"?>
    <Root>
      <AgencyName name="Some Agency" />
      <Originator name="Some other Agency" />
      <Type name="AnonymousType" />
      <Details>
        <Detail1>
               asdf
            </Detail1>
        <Detail2>
                asde
            </Detail2>
        <Detail3>
                eere
            </Detail3>
      </Details>
    </Root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am have two xml files.. I first get one and loop through it
I have two Nodes node1 and nod2 which have different parent documents, now I
I have to merge two xml documents using xslt 1.0. Each xml document has
I have some XML that looks something like this: <Root> <Documents> <Document id=1/> </Documents>
i have two opposing requirements related to an xml document and its related xsd.
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
Suppose I have two XML files. First XML File: <?xml version=1.0?> <AccessRequest xml:lang=en-US> <AccessLicenseNumber>Your_License</AccessLicenseNumber>
Is it a bad thing to have two xml columns in one table? +
I have created two folders layout and layout-land with two xml files, one for
I have these two xml documents: XML 1: <outer> <foo> <foo-child name=fA special=true> content

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.