XmlDocument vs XElement

  var xmlstr = @"
some_appid
1413192605
component_verify_ticket
some_verify_ticket
";


            Stopwatch sw = Stopwatch.StartNew();
            for (int i = 0; i < 1000; i++)
            {
                XmlDocument doc = new XmlDocument();
                doc.XmlResolver = null;
                XmlNode root;
                doc.LoadXml(xmlstr);
                root = doc.FirstChild;
                var sEncryptMsg = root["ComponentVerifyTicket"].InnerText;
            }
            sw.Stop();
            var docts = sw.ElapsedMilliseconds;

            sw.Restart();
            for (int i = 0; i < 1000; i++)
            {
                XElement xe = XElement.Parse(xmlstr);
                var sEncryptMsg = xe.Element("ComponentVerifyTicket").Value;
            }
            sw.Stop();
            MessageBox.Show(docts + "," +sw.ElapsedMilliseconds.ToString());

XmlDocumentd的耗时大概是XElement 的4倍以上

你可能感兴趣的:(XmlDocument vs XElement)