XDocument vs XmlDocument

StewartBW 1,145 Reputation points
2024-07-09T21:01:18.96+00:00

Hello experts,

To load and parse PAD xml from string which one is recommended to use, ie faster or more efficient?

XDocument.Root.Element("Program_Info")..Element("Program_Version")

XmlDocument.GetElementsByTagName("Program_Version")

Confused to choose one?

Sample PAD xml file to parse:

https://github.com/philc/InstallPad/blob/master/data/pad.xml

Thanks.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,040 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,741 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,451 Reputation points Microsoft Vendor
    2024-07-10T01:53:53.47+00:00

    Hi @StewartBW

    XDocument should be better for the following reasons:

    1. Supports LINQ queries, making it easier to navigate and query XML documents.
    2. More readable and easier to maintain.
    3. Better performance for large XML documents due to optimized parsing and querying.

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.