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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:47:21+00:00 2026-06-17T20:47:21+00:00

I have 2 xmls.SourceXml and TargetXml I am importing some elements of an xml

  • 0

I have 2 xmls.SourceXml and TargetXml

I am importing some elements of an xml into another xml.

That is all good however Some Elements I just need to change the name.
What I am currently doing I am building the element from scratch with the only difference is the name of the xml.

Let me give you an example.

In my Source Xml I have an element called

 <OldBank>
       <SortCode>123456</SortCode>
       <AccountNumber>12345678</AccountNumber>  
       etc....        
 </OldBank>

In My Target xml should be called NewBank with the children element that are exactly the same

  <NewBank>
       <SortCode>123456</SortCode>
       <AccountNumber>12345678</AccountNumber>  
       etc....        
 </NewBank>

This is what I do:

    public static void ReplaceNewCustomerDetails(this XDocument xDoc)
    {
        XElement oldBankElement = GetOldBankElement(xDoc);

       var newBakXml= new XElement("NewBank",
                     new XElement(oldBankElement.ElementOrDefault("SortCode")),
                     new XElement(oldBankElement.ElementOrDefault("AccountNumber")));

       //Build new xml. This is what I do
       var newXml = new XElement("MyNewXml");
       newXml.Add(newBakXml);

      //I wish I could just change the name of the xml rather then building it again
       var newXml = new XElement("MyNewXml");
       newXml.Add(oldBankElement.Name="NewBank");

Any suggestion or more elegant solution

Thanks

  • 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-17T20:47:22+00:00Added an answer on June 17, 2026 at 8:47 pm

    You don’t need to create new elements – just pass existing:

    var newBankXml = new XElement("NewBank", 
                                 oldBankElement.Attributes(), 
                                 oldBankElement.Elements());
    newXml.Add(newBankXml);
    

    Or simply change name:

    oldBankElement.Name = "NewBank";
    newXml.Add(oldBankElement);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to loop over all tags in a xml i have a php that
I have some autogenerated xmls where some parts of the xml may have multiple
The scenario: I have a servlet that receives xmls, parses them (using JAXB), persists
How to include a xml data into an other xml data? I have a
I have an XML serializer that works great for ASCII but when non-ASCII characters
I have the following xml, xmlDoc that looks like this: <root> <a> <Row> </a>
I have an app that I developed mainly for 10 inches. However, I need
I have to create object model for following XMLs: XML sample 1: <InvoiceAdd> <TxnDate>2009-01-21</TxnDate>
I have a splash activity, and this activity downloads some XMLs from the internet.
I have a Word 2010 template with some bookmarks and styles that I must

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.