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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:48:37+00:00 2026-05-12T15:48:37+00:00

I am now learning XmlDocument but I’ve just ran into XDocument and when I

  • 0

I am now learning XmlDocument but I’ve just ran into XDocument and when I try to search the difference or benefits of them I can’t find something useful, could you please tell me why you would use one over another ?

  • 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-12T15:48:37+00:00Added an answer on May 12, 2026 at 3:48 pm

    If you’re using .NET version 3.0 or lower, you have to use XmlDocument aka the classic DOM API. Likewise you’ll find there are some other APIs which will expect this.

    If you get the choice, however, I would thoroughly recommend using XDocument aka LINQ to XML. It’s much simpler to create documents and process them. For example, it’s the difference between:

    XmlDocument doc = new XmlDocument();
    XmlElement root = doc.CreateElement("root");
    root.SetAttribute("name", "value");
    XmlElement child = doc.CreateElement("child");
    child.InnerText = "text node";
    root.AppendChild(child);
    doc.AppendChild(root);
    

    and

    XDocument doc = new XDocument(
        new XElement("root",
                     new XAttribute("name", "value"),
                     new XElement("child", "text node")));
    

    Namespaces are pretty easy to work with in LINQ to XML, unlike any other XML API I’ve ever seen:

    XNamespace ns = "http://somewhere.com";
    XElement element = new XElement(ns + "elementName");
    // etc
    

    LINQ to XML also works really well with LINQ – its construction model allows you to build elements with sequences of sub-elements really easily:

    // Customers is a List<Customer>
    XElement customersElement = new XElement("customers",
        customers.Select(c => new XElement("customer",
            new XAttribute("name", c.Name),
            new XAttribute("lastSeen", c.LastOrder)
            new XElement("address",
                new XAttribute("town", c.Town),
                new XAttribute("firstline", c.Address1),
                // etc
        ));
    

    It’s all a lot more declarative, which fits in with the general LINQ style.

    Now as Brannon mentioned, these are in-memory APIs rather than streaming ones (although XStreamingElement supports lazy output). XmlReader and XmlWriter are the normal ways of streaming XML in .NET, but you can mix all the APIs to some extent. For example, you can stream a large document but use LINQ to XML by positioning an XmlReader at the start of an element, reading an XElement from it and processing it, then moving on to the next element etc. There are various blog posts about this technique, here’s one I found with a quick search.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The -h option also used to print to stderr because… May 12, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer LINQ solution: var rowIndexes = dgv.SelectedCells.Cast<DataGridViewCell>() .Select(cell => cell.RowIndex) .Distinct();… May 12, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer I need the actual XML as a string You want… May 12, 2026 at 9:17 pm

Related Questions

I am in early beginning of learning and deploying Win App using C#, Now
I am using TouchXml because of the given limitations of NSXML on the actual
In my attempt to learn core JavaScript, I am now learning about EventListeners. My
I am just now learning about function pointers and, as I was reading the
I have been learning Delphi for the last 3 years, on a hobby/occupational level.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.