李晓亮的博客

导航

【摘MSDN】使用C#创建Xml节点

代码
using System;
using System.IO;
using System.Xml;

public class Sample {
  
//http://technet.microsoft.com/zh-cn/system.xml.xmlnode.appendchild.aspx
  public static void Main() {

    XmlDocument doc 
= new XmlDocument();
    doc.LoadXml(
"<book genre='novel' ISBN='1-861001-57-5'>" +
                
"<title>Pride And Prejudice</title>" +
                
"</book>");

    XmlNode root 
= doc.DocumentElement;

    
//Create a new node.
    
//XmlNode elem = doc.CreateNode(XmlNodeType.Element, "price", null);
    XmlElement elem = doc.CreateElement("price");
    elem.InnerText
="19.95";

    
//Add the node to the document.
    root.AppendChild(elem);

    Console.WriteLine(
"Display the modified XML...");
    doc.Save(Console.Out);

  }
}

 

posted on 2010-10-20 18:21  LeeXiaoLiang  阅读(194)  评论(0)    收藏  举报