zoukankan      html  css  js  c++  java
  • C# 生成 XML

    XmlDocument doc = new XmlDocument();
    XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
    doc.AppendChild(dec);
    
    XmlElement root = doc.CreateElement("BookInfo");
    doc.AppendChild(root);
    
    XmlElement isbn = doc.CreateElement("ISBN");
    isbn.InnerText = "6926456900364";
    root.AppendChild(isbn);
    
    XmlElement bookTitle = doc.CreateElement("BookTitle");
    XmlCDataSection cd = doc.CreateCDataSection("杜拉拉3");
    bookTitle.AppendChild(cd);
    
    XmlAttribute suttitle = doc.CreateAttribute("Subtitle");
    suttitle.Value = "我在这战斗的一年里";
    bookTitle.Attributes.Append(suttitle);
    
    root.AppendChild(bookTitle);
    string xmlString = doc.OuterXml;
    doc.Save(@"c:\aa.xml");
    
    结果如下

    <?xml version="1.0" encoding="UTF-8" ?> 
    <BookInfo>
       
    <ISBN>6926456900364</ISBN> 
       
    <BookTitle Subtitle="我在这战斗的一年里"><![CDATA[杜拉拉3]]></BookTitle>
    </BookInfo>

  • 相关阅读:
    [BJOI2015]树的同构 && 树哈希教程
    「HNOI2014」世界树
    CF613D Kingdom and its Cities
    「HEOI2014」大工程
    虚树教程
    [SDOI2011]消耗战
    CF1216E Numerical Sequence
    vim8.1安装
    luoguP5024 保卫王国
    动态DP教程
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/1870345.html
Copyright © 2011-2022 走看看