致力于技术进步

专注于编程艺术

博客园 首页 新随笔 联系 订阅 管理

/********************************************************

    以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;

}

posted on 2009-12-10 10:30  stephen&amp;#183;周  阅读(152)  评论(0)    收藏  举报