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}\t{1} \n{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
 
 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值