博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
写XML
阅读量:4705 次
发布时间:2019-06-10

本文共 2108 字,大约阅读时间需要 7 分钟。

public void Index()        {            //先创建XML,返回路径            XmlDocument xmldoc = new XmlDocument();            XmlDeclaration xmldecl;            xmldecl = xmldoc.CreateXmlDeclaration("1.0", "utf-8", null);            xmldoc.AppendChild(xmldecl);            //加入一个根元素            XmlNode xmlelem = xmldoc.CreateElement("", "place", "");            xmldoc.AppendChild(xmlelem);            XmlNode root = xmldoc.SelectSingleNode("place");            DataSet dsp = ServiceManager.UserBuyCarService.GetProvince();            foreach (DataRow item in dsp.Tables[0].Rows)            {                XmlElement xe1 = xmldoc.CreateElement("Province");//创建:省                 xe1.SetAttribute("code", item["provinceId"].ToString());                xe1.SetAttribute("name", item["provinceName"].ToString());                DataSet dscity = ServiceManager.UserBuyCarService.GetCity(item["provinceId"].ToString());                foreach (DataRow city in dscity.Tables[0].Rows)                {                    XmlElement xcity = xmldoc.CreateElement("city");//创建:市                    xcity.SetAttribute("code", city["cityId"].ToString());                    xcity.SetAttribute("name", city["cityName"].ToString());                    DataSet dscounty = ServiceManager.UserBuyCarService.GetCounty(city["cityId"].ToString());                    foreach (DataRow county in dscounty.Tables[0].Rows)                    {                        XmlElement xcounty = xmldoc.CreateElement("area");//创建:区                        xcounty.SetAttribute("code", county["countyId"].ToString());                        xcounty.SetAttribute("name", county["countyName"].ToString());                        xcity.AppendChild(xcounty);                    }                    xe1.AppendChild(xcity);                }                root.AppendChild(xe1);            }            //然后在保存到源位置            xmldoc.AppendChild(xmlelem);            //保存创建好的XML文档            string m_strFilePath = "E:\\汽配2014.12.22" + @"\City2.xml";            xmldoc.Save(m_strFilePath);        }

 

转载于:https://www.cnblogs.com/juancreate2014/p/4428307.html

你可能感兴趣的文章
tomcat环境部署查看
查看>>
黑马程序员——网络编程
查看>>
Android底层开发技术实战详解——内核、移植和驱动
查看>>
《软件测试实战:微软技术专家经验总结》
查看>>
《学习OpenCV》课后习题解答6
查看>>
UIDatePicker
查看>>
python-基本数据类型之数字
查看>>
Codeforces 452E Three strings 字符串 SAM
查看>>
在XP系统中发布MVC3项目nopCommerce2.65及配置
查看>>
PHP开发异步高性能的MySQL代理服务器
查看>>
杭电之统计汉字
查看>>
笔记-Microsoft SQL Server 2008技术内幕:T-SQL语言基础-07 透视、逆透视及分组集
查看>>
贝叶斯分类器
查看>>
<img>标签
查看>>
python Anaconda
查看>>
第三十五节(java-动态加载级联菜单)
查看>>
android:intent flags
查看>>
SVPWM实现概述
查看>>
Android实现隐藏状态栏和标题栏
查看>>
Vue疑难杂症
查看>>