首页 > 其他 > 详细

创建带属性的XML文档

时间:2016-10-25 01:47:23      阅读:208      评论:0      收藏:0      [点我收藏+]
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace 创建带属性的XML文档
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
            doc.AppendChild(dec);

            XmlElement order = doc.CreateElement("Order");
            doc.AppendChild(order);

            XmlElement customerName = doc.CreateElement("CustomerName");
            customerName.InnerText = "肚子好饿";
            order.AppendChild(customerName);

            XmlElement items = doc.CreateElement("Items");
            order.AppendChild(items);

            XmlElement orderItem1 = doc.CreateElement("orderItem");
            orderItem1.SetAttribute("Name", "炒粉干");
            orderItem1.SetAttribute("Count", "2");
            items.AppendChild(orderItem1);

            doc.Save("Order.xml");
            Console.WriteLine("保存成功");
            Console.ReadKey();
        }
    }
}

 

创建带属性的XML文档

原文:http://www.cnblogs.com/blacop/p/5995084.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!