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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:40:35+00:00 2026-05-25T16:40:35+00:00

I’m using .NET C# XML and LINQ to Update/delete/insert my XML file. I’ve got

  • 0

I’m using .NET C# XML and LINQ to Update/delete/insert my XML file.

I’ve got an XML file looks like below (image1) and I would like to inlcude just the 2nd XML file.

The first XML file is the original file and I don’t want to touch this file. So I prefer a reference to a 2nd. file (external file) so I can add/remove XML lines there in stead of the Mainf XML file.

But how can do include or merge the 2nd XML (External file) in to the FIRST?
I just need to the tags (see RED box) from see in RED box.

<RewriterRule>
   <LookFor>        </LookFor>
   <SendTo>         </SendTo>
</RewriterRule>

Question:

1- What do I need to write for code in XML file 1 so my code in XMLfile 2 (external file) is included?

2- How should my XMLfile 2 (external file) look like? In fact I need the tags I think, because I’m reading the XML XDocument xdoc = XDocument.Load(this.Server.MapPath(path));and doing some update/deletes…..

Original file

IMAG2 – EXTERNAL FILE
enter image description here

  • 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-25T16:40:36+00:00Added an answer on May 25, 2026 at 4:40 pm

    Well adding elements from a second file is easy:

    XDocument doc1 = XDocument.Load(MapPath("file1.xml"));
    doc1.Root.Element("Rules").Add(XDocument.Load(MapPath("file2.xml")).Root.Element("Rules").Elements("RewriterRule"));
    
    // now save to third file with e.g.
    doc1.Save(MapPath("updated.xml"));
    // or overwrite first file e.g.
    doc1.Save(MapPath("file1.xml"));
    

    On the other hand the term “merging” suggests you might want to do something more complex like identifying elements based on some id or key and then not simply add new elements but overwrite some data. You will need to provide more details on exactly what kind of merge process you want if you need help with writing the code.

    [edit] Here is an example on how to use the DTD based mechanism of a reference to an external entity to include an XML fragment file into another document: file1.xml is as follows:

    <!DOCTYPE example [
      <!ENTITY e1 SYSTEM "fragment.xml">
    ]>
    <example>
      <data>
        <item>1</item>
        &e1;
      </data>
    </example>
    

    fragment.xml is as follows:

    <?xml version="1.0" encoding="utf-8" ?>
    <item>2</item>
    

    Then, when reading in the main file with LINQ to XML and .NET 4.0 you need to make sure the XmlReader you use is set to parse the DTD e.g.

            XDocument doc;
            using (XmlReader xr = XmlReader.Create("file1.xml", new XmlReaderSettings() { DtdProcessing = System.Xml.DtdProcessing.Parse }))
            {
                doc = XDocument.Load(xr);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.