我对此问题有点困惑。使用磁盘中的文件运行XDocument.Load
时,调用将在几毫秒内完成。但是如果我们使用相同的数据但是从XMLNodeReader
拨打电话,则需要超过6分钟。任何帮助,将不胜感激。谢谢!
请参阅以下代码:
XDcoument.Load from File
private static string SerializeData(Data data)
{
var serializer = new XmlSerializer(typeof(Data));
var dataXmlDocument = new XmlDocument();
using (XmlWriter writer = dataXmlDocument.CreateNavigator().AppendChild())
{
serializer.Serialize(writer, data);
}
dataXmlDocument.Save("C:/test.xml");
var dataXDocument = new XDocument();
dataXDocument = XDocument.Load(File.OpenRead("C:\test.xml");
}
来自XMLNodeReader的XDocument.Load
private static string SerializeData(Data data)
{
var serializer = new XmlSerializer(typeof(Data));
var dataXmlDocument = new XmlDocument();
using (XmlWriter writer = dataXmlDocument.CreateNavigator().AppendChild())
{
serializer.Serialize(writer, data);
}
var dataXDocument = new XDocument();
using (var nodeReader = new XmlNodeReader(dataXmlDocument))
{
nodeReader.MoveToContent();
dataXDocument = XDocument.Load(nodeReader);
}
}