VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • XmlDocument vs XElement

  var xmlstr = @"<xml>
<AppId>some_appid</AppId>
<CreateTime>1413192605</CreateTime>
<InfoType>component_verify_ticket</InfoType>
<ComponentVerifyTicket>some_verify_ticket</ComponentVerifyTicket>
</xml>";


            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倍以上


相关教程