Kirk Evans Blog

.NET From a Markup Perspective

What’s Wrong With XmlDocument?

So, what’s wrong with System.Xml.XmlDocument in .NET?  Plenty, according to Joshua Prismon:

To use XMLDocument and Datasets, you have to have the full tree in memory.

If you are concerned about loading only branches of data at a time, the System.Xml namespace provides all the classes that you could possibly need.  And for the ones you dream up, the System.Xml namespace provides a wealth of flexibility.

XmlTextReader reader = new XmlTextReader(Server.MapPath(“data/mediumdoc.xml”));
  string id = reader.GetAttribute(“id”);
  if(null != id && id.CompareTo(“3”) == 0)
    XmlDocument doc = new XmlDocument();

    //Do something interesting with DOM model here
    Response.ContentType = “text/xml”;