开发者

LINQ to XML X-DOM internal implementation

How is the LINQ to XML X-DOM from the System.Xml.Linq namespace internall开发者_如何学Goy implemented? (XNode, XElement, etc.)

Is it utilizing standard high-performing one-way XmlReader/XmlWriter from the other XML namespaces or something else?

The reason I'm asking is that I'm trying to figure out in which circumstances could or should be used as performance is always a concern.


Using Reflector (or, when that's no longer free, ILSpy :); no I'm not an employee - just spreading the word surreptitiously!) it appears all the load/save methods channel through to XmlReader and XmlWriter. For example - XElement's implementation of Load(Stream, LoadOptions) does this:

public static XElement Load(Stream stream, LoadOptions options)
{
  XmlReaderSettings xmlReaderSettings = XNode.GetXmlReaderSettings(options);
  using (XmlReader reader = XmlReader.Create(stream, xmlReaderSettings))
  {
    return Load(reader, options);
  }
}

And it's a similar story for all the other static methods - including Parse.

But then there is the XStreamingElement constructor - however I can't find any real usage of it outside of the XElement class itself. Looks like this could be an optimised type for loading that, as yet, isn't used by much.

Equally, the Save and WriteTo methods ultimately use an XmlWriter instance - e.g:

public void Save(string fileName, SaveOptions options)
{
  XmlWriterSettings xmlWriterSettings = XNode.GetXmlWriterSettings(options);
  using (XmlWriter writer = XmlWriter.Create(fileName, xmlWriterSettings))
  {
    this.Save(writer);
  }
}

So at least from a performance point of view they started with the right types :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜