博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建带属性的XML文档
阅读量:7173 次
发布时间:2019-06-29

本文共 1106 字,大约阅读时间需要 3 分钟。

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();        }    }}

 

转载于:https://www.cnblogs.com/blacop/p/5995084.html

你可能感兴趣的文章
CSS选择器 < ~ +
查看>>
Opengl_es模型矩阵位置:glFrustumx与glTranslatef参数的相互影响--立方体旋转特效
查看>>
JS小功能系列8省市联动
查看>>
《程序是怎样跑起来的》第八章读后感
查看>>
YCD 软件更新方法
查看>>
CentOS 6.5 + Nginx 1.8.0 + PHP 5.6(with PHP-FPM) 负载均衡源码安装 之 (四)问题汇总
查看>>
mybatis中的#和$的区别
查看>>
synchronized 解决死锁的问题 轉貼
查看>>
poj2524(并查集)买一送一hdu1213
查看>>
ADO.NET详解----核心对象的使用
查看>>
ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)
查看>>
如何让linux定时任务crontab按秒执行
查看>>
yaf代码生成工具的使用
查看>>
Scrum方法论(四)
查看>>
程序员,请不要抢系统管理员的饭碗
查看>>
第10章代码《跟老男孩学习Linux运维:Shell编程实战》
查看>>
redux-form(V7.4.2)笔记(一)
查看>>
linux下批量修改文件名精彩解答案例分享
查看>>
背锅侠逆袭之路
查看>>
运维人员如何学好shell脚本编程
查看>>