DataSet To XmlDocument

public static XmlDocument BuildXml(DataSet ds)
    {
        XmlDocument doc = new XmlDocument();
        MemoryStream mStrm = new MemoryStream();
        StreamReader sRead = new StreamReader(mStrm);
        //   调用WriteXml方法把DataSet中的数据输出     
        //不包含架构   
        ds.WriteXml(mStrm, XmlWriteMode.IgnoreSchema);

        //包含架构   
        //ds.WriteXml(mStrm, XmlWriteMode.WriteSchema);

        //ds.WriteXml(mStrm, XmlWriteMode.DiffGram);
        //   从数据流的开始位置进行搜索     
        mStrm.Seek(0, SeekOrigin.Begin);
        //   将数据流加载到XmlDocument     
        doc.Load(sRead);
        return doc;
    } 

posted @ 2011-05-07 16:13  likunran  阅读(143)  评论(0编辑  收藏  举报