zoukankan      html  css  js  c++  java
  • Generate XML file

    View Code
    private void btnCreateXML_Click(object sender, EventArgs e)
    {
    XmlDocument doc
    = new XmlDocument();
    doc.LoadXml(
    "<xml version=\"1.0\" encoding=\"utf-8\" />");

    XmlElement newElem
    = doc.CreateElement("price");
    newElem.InnerText
    = "10.95";
    doc.DocumentElement.AppendChild(newElem);

    XmlElement childElem1
    = doc.CreateElement("Item1");
    doc.DocumentElement.AppendChild(childElem1);

    XmlElement childElem2
    = doc.CreateElement("Item2");
    doc.DocumentElement.AppendChild(childElem2);
    doc.Save(
    "test.xml");

    lblMessage.Text
    = "Generate xml file sucessfully!";
    }

    private void button1_Click(object sender, EventArgs e)
    {
    XmlDocument doc
    = new XmlDocument();
    doc.LoadXml(
    "<book>" +
    " <title>Oberon's Legacy</title>" +
    " <price>5.95</price>" +
    "</book>");

    // Create a new element node.
    XmlNode newElem = doc.CreateNode("element", "pages", "");
    newElem.InnerText
    = "";

    Console.WriteLine(
    "Add the new element to the document...");
    XmlElement root
    = doc.DocumentElement;
    root.AppendChild(newElem);

    XmlNode newElem1
    = doc.CreateNode("element", "pages", "");
    newElem1.InnerText
    = "";


    newElem.AppendChild(newElem1);

    Console.WriteLine(
    "Display the modified XML document...");
    Console.WriteLine(doc.OuterXml);
    }
  • 相关阅读:
    Tomcat启动流程简析
    Tomcat的启停脚本源码解析
    Servlet规范
    CCNA
    CCNA-Part 6
    MYSQL 使用基础
    CCNA-Part5
    CCNA-Part4 -网络层
    MySQL 字符串索引优化方案
    CCNA-Part3
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/2088481.html
Copyright © 2011-2022 走看看