Forget XmlDocument and XPath. LINQ to XML (XDocument) is the faster, cleaner, and more LINQ-friendly way to handle XML in .NET.
You can 'build' an entire XML document using a single functional expression. No more CreateElement, AppendChild boilerplate.
var doc = new XDocument(
new XElement("Users",
from u in users
select new XElement("User",
new XAttribute("Id", u.Id),
new XElement("Name", u.Name)
)
)
);
Finding an element is as simple as doc.Descendants("User").Where(...). It feels exactly like querying a database or an in-memory list.
Q: "Is it faster than XPath?"
Architect Answer: "In most cases, yes. LINQ to XML uses a much lighter memory model than the old XmlDocument (DOM). It's also much harder to make 'String-based' errors that you frequently see with XPath. Use XDocument for all modern XML work until you move to System.Text.Json for JSON-based projects."