/********************************************************
以xml数据源的方式生成xml文档
*********************************************************/
public void CreateXMlDataSource()
{
//文档声明、根节点定义
XmlDocument xmlDocument = new XmlDocument();//表示XML文档
XmlDeclaration xde;//<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
xde = xmlDocument.CreateXmlDeclaration("1.0", null, null);
xde.Encoding = "utf-8";
xde.Standalone = "yes";
xmlDocument.AppendChild(xde);
XmlElement xmlRootElement= xmlDocument.CreateElement(根节点);//
xmlDocument.AppendChild(xmlRootElement);//Root根元素创建完成
//构建一个数据源对象(xml,ArrayList,数据库,外部数据源...)
foreach(...)//遍历数据源
{
XmlElement sonNodeElement= xmlDocument.CreateElement("子节点");//在<Root>之下创建元素<TreeNode>
sonNodeElement.SetAttribute(节点属性,节点值)
sonNodeElement.SetAttribute(节点属性,节点值).....///
..
..
xmlRootElement.AppendChild(sonNodeElement)
}
return xmlDocument.OuterXml;
}
浙公网安备 33010602011771号