我如何重用xml创建 [英] How do i reuse xml creation

查看:63
本文介绍了我如何重用xml创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在我的项目中使用融合图表.它以xml字符串的形式获取数据,因此当前我为每个图表创建动态xml字符串.由于图表太多,似乎我已经结束了编写重复的同类代码,

hi all,
i am using fusion charts in my project.it takes data in the form of xml string,so currently for each chart i create dynamic xml string.since there are too many charts,seems i have ended up writing repeated kinda code,

 xmlData.Append("<chart showLegend='1' bgColor='FFFFFF' caption='Project Type:"+ strprojtyp
+ "' subCaption='% of Backlog Hours For Job Codes'"

+ " palette='2' animation='0' formatNumberScale='0' pieSliceDepth='30' startingAngle='125' showBorder='0' showpercentvalues='1'"

+ " showlabels='0' legendNumColumns='2' legendPosition='BOTTOM' minimiseWrappingInLegend='0' enablesmartlabels='0' exportEnabled='1' exportAtClient='0' exportFileName='" + GetFileName(true) + "'"

+ " exportAction='save' exportHandler='" + HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
                    + HttpRuntime.AppDomainAppVirtualPath
                    + "/App/LPMN/FCExporter.aspx'>");



除了标题和导出处理程序以及我将数据绑定到它的数据表之外,这里没有任何变化,



nothing changes here except caption and export handler and the datatable which i bind the data to it,

 foreach (DataTable dtable in ds.Tables)
   {
xmlData.Append("<set label='" + dtable.TableName + "' value='" + dtable.Rows[0][0].ToString()
 + "' link='j-linkChart-" + strsplt[0] + "~" + strsplt[1] + "'/>");
   }



有什么办法可以避免重复创建xml字符串.

感谢您的所有帮助,



is there any way i can avoid the repeated xml string creation.

thanks for all your help,

推荐答案

定义一个方法,该方法可生成您的字符串并将变量项作为参数传递!
define a method that generates your string and pass in your variable terms as parameters!



1.为XML的不可更改元素创建预定义的HEADER字符串值
2.在foreach循环中,您可以将所需的DATA结果生成为字符串
3.在HEADER字符串内连接您的DATA字符串
然后,您可以轻松地将字符串转换为XML

--Sowraaj


1.Create a predefined HEADER string value for unchangeable elements of your XML
2.In your foreach loop, you can generate the required DATA results as string
3.Concatenate your DATA string inside the HEADER string
and then,you can easily convert the string as XML

--Sowraaj


这篇关于我如何重用xml创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆