1、xml字符串示例
<?xml version="1.0" encoding="utf-8" standalone="no"?><DATA><ITEMS><ITEM><ID>01<ID/><CODE>0001<CODE><NAME>测试1<NAME/></ITEM></ITEMS></DATA>
2、方法
private string Getxml()
{
XmlDocument document = new XmlDocument();
XmlDeclaration xd = document.CreateXmlDeclaration("1.0", "utf-8", "");
XmlElement root = null;
document.AppendChild(document.CreateElement("DATA"));
root = document.DocumentElement;
document.InsertBefore(xd, root);
XmlElement items = document.CreateElement("ITEMS");
XmlElement item = document.CreateElement("ITEM");
items .AppendChild(item);
XmlElement id = document.CreateElement("ID");
item.AppendChild(id);
XmlElement code = document.CreateElement("CODE");
item.AppendChild(code);
XmlElement code = document.CreateElement("NAME");
item.AppendChild(name);
root.AppendChild(items);
string xmlData = document.OuterXml;
//存xml
if (!string.IsNullOrEmpty(xmlData))
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlData);
string filepath = "C:\\Test\\test.xml";
doc.Save(filepath);
}
return xmlData;
}