c#之xml

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO; namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// XmlDocument doc = new XmlDocument();
// //创建描述信息,并且添加到doc文档中
// XmlDeclaration dc=doc.CreateXmlDeclaration("1.0", "utf-8", null);
// doc.AppendChild(dc);
// //添加根节点
// XmlElement nodes = doc.CreateElement("Books");
// doc.AppendChild(nodes);
////添加子节点
// XmlElement book1 = doc.CreateElement("book");
// nodes.AppendChild(book1);
// XmlElement book2 = doc.CreateElement("name");
// book2.InnerText = "假如sssx";
// book1.AppendChild(book2); // XmlElement book3 = doc.CreateElement("price");
// book1.AppendChild(book3);
// book3.InnerText = "600";
// XmlElement book4 = doc.CreateElement("dec");
// book1.AppendChild(book4);
// book4.InnerText = "6sdasdsadsad"; // XmlElement book5 = doc.CreateElement("book");
// nodes.AppendChild(book5);
// XmlElement book6 = doc.CreateElement("name");
// book6.InnerText = "假如";
// book5.AppendChild(book6); // XmlElement book7 = doc.CreateElement("price");
// book5.AppendChild(book7);
// book7.InnerText = "60";
// XmlElement book8 = doc.CreateElement("dec");
// book5.AppendChild(book8);
// book8.InnerText = "6sdasdsadsad"; // doc.Save("kiven.xml"); // Console.ReadKey();
XmlDocument doc = new XmlDocument();
XmlDeclaration dc = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");
doc.AppendChild(dc);
XmlElement order = doc.CreateElement("Order");
doc.AppendChild(order);
XmlElement Cu = doc.CreateElement("CustomerName");
order.AppendChild(Cu);
Cu.InnerText = "张三";
XmlElement cust=doc.CreateElement("customerNumber1");
cust.InnerText = "100";
order.AppendChild(cust);
XmlElement item = doc.CreateElement("Items");
order.AppendChild(item);
XmlElement orders = doc.CreateElement("OrderItem");
orders.SetAttribute("Name", "码表");
orders.SetAttribute("Count", "20");
item.AppendChild(orders);
XmlElement orders1 = doc.CreateElement("OrderItem");
item.AppendChild(orders1);
XmlElement orders2 = doc.CreateElement("OrderItem");
item.AppendChild(orders2);
doc.Save("a.xml");
Console.ReadKey(); }
}
}

  

上一篇:搜集几个API接口


下一篇:python3学习笔记十(循环语句)