惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
J
Java Code Geeks
Jina AI
Jina AI
罗磊的独立博客
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
D
DataBreaches.Net
博客园 - 叶小钗
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
B
Blog
V
Visual Studio Blog
雷峰网
雷峰网
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - 水乐天

exe文件关联失效 win7 无法支持接口 软件版本说明 WebService的时间问题,大家都注意一下 - 水乐天 - 博客园 C#在线备份数据库至制定目录 - 水乐天 - 博客园 解决图片占用的问题 比较全的字符串验证类,有人顶的话以后继续发 小沈阳版程序员的痛苦 Code39条形码类 C#如何判断同网段计算机是否存在 如何注册FLASH控件 好用的XML Log类 键盘上各键位所对应的ASCII码详单(键盘键位表) 非Excel com 的Excel导出方法 C#调用VC DLL 复杂结构 解决方法 分类问题 AxWindowsMediaPlayer媒体文件主要方法属性 FLASH+XML+ASP.Net轮换广告源代码 .Net没有写权限,无法找到资源解决方法 IceUfo中小型企业门户
用DataSet生成指定格式的XML
水乐天 · 2008-08-18 · via 博客园 - 水乐天

最近用FLASH调用DataSet生成的XML发现DataSet的XML都有固定格式,网上也没有太好的方法,于是自己写了下给大家参考

 protected void Page_Load(object sender, EventArgs e)
    {
        TBLL.TSlide slidebll 
= new TBLL.TSlide(); 
        DataSet ds 
=  slidebll.GetAllList();
        XmlDataDocument xdd 
= SetItemsCountAttribute(ds);
        Response.Clear();
        xdd.Save(Response.OutputStream);
        Response.End();
    }
    
private XmlDataDocument SetItemsCountAttribute(DataSet ds)
    {
        
try
        {
            XmlDataDocument xmlDoc;
            
int ItemCount = 0;

            ds.DataSetName 

= strRootNodeName;
            ds.EnforceConstraints 
= false;
            xmlDoc 
= new XmlDataDocument();

            XmlNode xmlDocNode 

= xmlDoc.CreateXmlDeclaration("1.0""UTF-8"null);
            xmlDoc.AppendChild(xmlDocNode);

            XmlNode viewer 

= xmlDoc.CreateElement("viewer");
            XmlAttribute interval 
= xmlDoc.CreateAttribute("interval");
            interval.Value 
= "4000";
            viewer.Attributes.Append(interval);
            XmlAttribute isRandom 
= xmlDoc.CreateAttribute("isRandom");
            isRandom.Value 
= "1";
            viewer.Attributes.Append(isRandom);
            xmlDoc.AppendChild(viewer);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                XmlNode item 
= xmlDoc.CreateElement("item");
                XmlAttribute title 
= xmlDoc.CreateAttribute("title");
                title.Value 
= ds.Tables[0].Rows[i]["Title"].ToString();
                item.Attributes.Append(title);
                XmlAttribute img 
= xmlDoc.CreateAttribute("img");
                img.Value 
= ds.Tables[0].Rows[i]["ImgUrl"].ToString();
                item.Attributes.Append(img);
                XmlAttribute url 
= xmlDoc.CreateAttribute("url");
                url.Value 
= ds.Tables[0].Rows[i]["LinkUrl"].ToString();
                item.Attributes.Append(url);
                XmlAttribute target 
= xmlDoc.CreateAttribute("target");
                target.Value 
= "_blank";
                item.Attributes.Append(target);
                viewer.AppendChild(item);
            }
return xmlDoc;
        }
        
catch (Exception e)
        {
            
string strMsg = e.Message;
            
return null;
        }
    }