LoadXml:从指定的字符串加载 XML 文档。
eg:doc.LoadXml("aa ");
public void LoadXmlTest() { // Create the XmlDocument. XmlDocument doc = new XmlDocument(); doc.LoadXml("Load:加载指定的 XML 数据- "); // 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); }
wrench
从指定的流加载 XML 文档。
从指定的 URL 加载 XML 文档。 从指定的 加载 XML 文档。从指定的 加载 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(); }