zoukankan      html  css  js  c++  java
  • XmlDocument.LoadXml和Load的区别

    LoadXml:从指定的字符串加载 XML 文档。

    eg:doc.LoadXml("<root>aa</root>");

           public void LoadXmlTest() {
                // Create the XmlDocument.
                XmlDocument doc = new XmlDocument();
                doc.LoadXml("<item><name>wrench</name></item>");
    
                // Add a price element.
                XmlElement newElem = doc.CreateElement("price");
                newElem.InnerText = "10.95";
                doc.DocumentElement.AppendChild(newElem);
    
                XmlNode xmlNode = doc.SelectSingleNode("/item/name");
                Console.WriteLine(xmlNode.InnerText);
                xmlNode = doc.SelectSingleNode("/item/price");
                Console.WriteLine(xmlNode.InnerText);
    
                // Save the document to a file and auto-indent the output.
                XmlTextWriter writer = new XmlTextWriter("data.xml", null);
                writer.Formatting = Formatting.Indented;
                doc.Save(writer);
            }

    Load:加载指定的 XML 数据

    XmlDocument.Load (Stream)从指定的流加载 XML 文档。
    XmlDocument.Load (String) 从指定的 URL 加载 XML 文档。
    XmlDocument.Load (TextReader) 从指定的 TextReader 加载 XML 文档。
    XmlDocument.Load (XmlReader)从指定的 XmlReader 加载 XML 文档。

            public void getInfo(string fileName)
            {
                //创建XML的根节点
               // CreateXMLElement();
                string fileFullPath = Application.StartupPath + "\" + fileName;
                Console.WriteLine(fileFullPath);
                XmlDocument doc = new XmlDocument();
                doc.Load(fileFullPath);
    
    
                XmlNodeList xmlNodeList = doc.SelectNodes("/root/business/item");
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    Console.WriteLine(string.Format("{0}	{1} 
    {2}", xmlNode.Attributes["BusinessName"].Value, xmlNode.Attributes["DistinctionKey"].Value, xmlNode.Attributes["Url"].Value));
                }
    
                Console.ReadLine();
            }
     
    http://msdn.microsoft.com/zh-cn/library/system.xml.xmldocument.loadxml(VS.80).aspx
     
     
     

  • 相关阅读:
    LDAP安装配置(windows)
    chrome postman插件手动安装
    mabatis insert into on duplicate key
    ZOJ 3641 <并查集+STL>
    ZOJ 3633 <rmq 重点在于转化>
    POJ 2817 状态DP 字符串找最多的重复
    POJ 2771 简单二分图匹配
    POJ 1149 最大流<建图> PIGS
    POJ 3692 二分图最大独立点集
    POJ 2239 简单的二分图求最大匹配
  • 原文地址:https://www.cnblogs.com/softidea/p/3347326.html
Copyright © 2011-2022 走看看