假设一个xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.xxx.com/XxxSystem">
<Person id="1">
<Name>张三</Name>
<Age>18</Age>
</Person>
<Person id="2">
<Name>李四</Name>
<Age>20</Age>
</Person>
</Persons>
1)XmlDocument方式
创建xml代码如下:
private void button1_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(dec);
//根节点
XmlElement root = doc.CreateElement("Persons"