XDocument vs XmlDocument

StewartBW 1,765 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.

Developer technologies VB
Developer technologies C#
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    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.