zoukankan      html  css  js  c++  java
  • 创建xml树

    XMLElement 节点
    XMLDocument 节点的CUID操作

    XMLNode 抽象类 操作节点 (XMLElement XMLDocument )

    XElement xElement = new XElement(
    new XElement("BookStore",
    new XElement("Book",
    new XElement("Name", "C#入门", new XAttribute("BookName", "C#")),
    new XElement("Author", "Martin", new XAttribute("Name", "Martin")),
    new XElement("Adress", "上海"),
    new XElement("Date", DateTime.Now.ToString("yyyy-MM-dd"))
    ),
    new XElement("Book",
    new XElement("Name", "WCF入门", new XAttribute("BookName", "WCF")),
    new XElement("Author", "Mary", new XAttribute("Name", "Mary")),
    new XElement("Adress", "北京"),
    new XElement("Date", DateTime.Now.ToString("yyyy-MM-dd"))
    )
    )
    );

    //需要指定编码格式,否则在读取时会抛:根级别上的数据无效。 第 1 行 位置 1异常
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Encoding = new UTF8Encoding(false);
    settings.Indent = true;
    XmlWriter xw = XmlWriter.Create(xmlPath, settings);
    xElement.Save(xw);
    //写入文件
    xw.Flush();
    xw.Close();

  • 相关阅读:
    随便练习的进制转换
    回顾快速排序
    常用c++函数
    POJ 1163 The Triangle
    HDU 1155 Bungee Jumping
    ZOJ 3861 Valid Pattern Lock
    POJ 1273 Drainage Ditches
    Hrbust 2240 土豪的时代
    POJ 3468 A Simple Problem with Integers
    POJ 1061 青蛙的约会
  • 原文地址:https://www.cnblogs.com/mmbbflyer/p/7715199.html
Copyright © 2011-2022 走看看