关于C#程序中插入值放XML文件中,我要在XML中显示的格式如下:
<newnode name="A">
<information>小明在中午吃饭啦</information>
<information>阿黄在中午被狗咬啦</information>
......
</newnode>
<newnode name="B">
<information>阿黄在中午吃饭啦</information>
<information>小强在中午被狗咬啦</information>
......
</newnode>
......
请问如何把要插入的值在XML文件中如上显示谢谢。。很急!!!解决立马给分!不清楚问题我可以继续描述!
<newnode name="A">
<information>小明在中午吃饭啦</information>
<information>阿黄在中午被狗咬啦</information>
......
</newnode>
<newnode name="B">
<information>阿黄在中午吃饭啦</information>
<information>小强在中午被狗咬啦</information>
......
</newnode>
......
请问如何把要插入的值在XML文件中如上显示谢谢。。很急!!!解决立马给分!不清楚问题我可以继续描述!
看看这个链接,提供了多种xml文件读、写操作的方法。
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
XmlNode root = doc.DocumentElement;
XmlElement parent = doc.CreateElement("newnode");
parent.SetAttribute("name","A"); XmlElement child = doc.CreateElement("information");
child.InnerText = "小明在中午吃饭啦 ";
parent.AppendChild(child);
child = doc.CreateElement("information");
child.InnerText = "阿黄在中午被狗咬啦 ";
parent.AppendChild(child); root.AppendChild(parent); parent = doc.CreateElement("newnode");
parent.SetAttribute("name", "B"); child = doc.CreateElement("information");
child.InnerText = "阿黄在中午吃饭啦 ";
parent.AppendChild(child);
child = doc.CreateElement("information");
child.InnerText = "小强在中午被狗咬啦 ";
parent.AppendChild(child);
root.AppendChild(parent); doc.Save("test.xml");
}
保存的test.xml:<?xml version="1.0" encoding="utf-8"?>
<root>
<newnode name="A">
<information>小明在中午吃饭啦 </information>
<information>阿黄在中午被狗咬啦 </information>
</newnode>
<newnode name="B">
<information>阿黄在中午吃饭啦 </information>
<information>小强在中午被狗咬啦 </information>
</newnode>
</root>