根据SQL语句生成同一类型的XML文件
2011-01-16 13:49
513 查看
/// <summary>
/// 根据SQL语句生成同一类型的XML文件
/// </summary>
/// <param name="sql">sql</param>
/// <param name="fileName">文件名</param>
/// <param name="fatherName">父节点</param>
/// <param name="childName1">子节点1</param>
/// <param name="childName2">子节点2</param>
public void CreateXmlBySql(string sql, string fileName, string fatherName, string childName1, string childName2)
{
HttpServerUtility Server;
DataTable dt = new DataTable();
Server = HttpContext.Current.Server;
XmlDocument xml = new XmlDocument();
XmlElement xmlFather, xmlChild1, xmlChild2;
xml.LoadXml(@"<xml name=""StockGrade"" version=""1.0"" encoding=""utf-8"" />");
XmlElement r = xml.DocumentElement;//创建一个XML对象
dt = Global.busLogicInner.GetPJBySql(sql);//根据sql语句获取数据
if (dt != null)
{
foreach (var col in from v in dt.AsEnumerable() select v)
{
xmlFather = xml.CreateElement(fatherName);
xmlChild1 = xml.CreateElement(childName1);
xmlChild1.InnerText = col[childName1].ToString();
xmlFather.AppendChild(xmlChild1);
xmlChild2 = xml.CreateElement(childName2);
xmlChild2.InnerText = col[childName2].ToString();
xmlFather.AppendChild(xmlChild2);
r.AppendChild(xmlFather);
}
xmlFather = xml.CreateElement(fatherName);
xmlChild1 = xml.CreateElement(childName1);
xmlChild1.InnerText = "END";
xmlFather.AppendChild(xmlChild1);
xmlChild2 = xml.CreateElement(childName2);
xmlChild2.InnerText = "END";
xmlFather.AppendChild(xmlChild2);
r.AppendChild(xmlFather);
string filePath = Server.MapPath(fileName);
if (File.Exists(filePath))
File.Delete(filePath);
xml.Save(filePath);
}
}
/// 根据SQL语句生成同一类型的XML文件
/// </summary>
/// <param name="sql">sql</param>
/// <param name="fileName">文件名</param>
/// <param name="fatherName">父节点</param>
/// <param name="childName1">子节点1</param>
/// <param name="childName2">子节点2</param>
public void CreateXmlBySql(string sql, string fileName, string fatherName, string childName1, string childName2)
{
HttpServerUtility Server;
DataTable dt = new DataTable();
Server = HttpContext.Current.Server;
XmlDocument xml = new XmlDocument();
XmlElement xmlFather, xmlChild1, xmlChild2;
xml.LoadXml(@"<xml name=""StockGrade"" version=""1.0"" encoding=""utf-8"" />");
XmlElement r = xml.DocumentElement;//创建一个XML对象
dt = Global.busLogicInner.GetPJBySql(sql);//根据sql语句获取数据
if (dt != null)
{
foreach (var col in from v in dt.AsEnumerable() select v)
{
xmlFather = xml.CreateElement(fatherName);
xmlChild1 = xml.CreateElement(childName1);
xmlChild1.InnerText = col[childName1].ToString();
xmlFather.AppendChild(xmlChild1);
xmlChild2 = xml.CreateElement(childName2);
xmlChild2.InnerText = col[childName2].ToString();
xmlFather.AppendChild(xmlChild2);
r.AppendChild(xmlFather);
}
xmlFather = xml.CreateElement(fatherName);
xmlChild1 = xml.CreateElement(childName1);
xmlChild1.InnerText = "END";
xmlFather.AppendChild(xmlChild1);
xmlChild2 = xml.CreateElement(childName2);
xmlChild2.InnerText = "END";
xmlFather.AppendChild(xmlChild2);
r.AppendChild(xmlFather);
string filePath = Server.MapPath(fileName);
if (File.Exists(filePath))
File.Delete(filePath);
xml.Save(filePath);
}
}
相关文章推荐
- oracle sql语句根据交易类型生成统计报表...
- Django中关于根据配置生成SQL语句的问题
- Excel2007根据SQL语句生成透视图的一些关键点
- 根据表名自动生成INSERT,UPDATE,DELETE,SELECT的SQL语句
- 根据DELTA自动生成SQL语句
- 反射+注释,根据实体类对象生成SQL语句工具类
- 缓存收录二: 用一个类根据Model属性生成SQL语句
- 根据反射生成SQL语句
- 根据基本表结构及其数据生成SQL语句
- 根据实体自动生成sql语句并且执行
- 根据表名自动生成INSERT,UPDATE,DELETE,SELECT的SQL语句
- SQL语句:orac 3ff0 le中如何插入Date类型的数据和根据Date数据进行查询的方法
- 在Delphi中根据SQL Server表名和表描述生成SQL语句
- 收藏:如何根据当前MDB中的表生成对应的JET SQL DDL “CREATE TABLE”语句/脚本?
- 根据实体自动生成sql语句并且执行
- 根据Model有值的自动生成添加的Sql语句
- java 根据实体对象生成 增删改的SQL语句 ModelToSQL
- 根据SQL语句生成文本文件
- (转载)根据数据字典表定义的表结构,生成创建表的SQL语句
- 反射+注释,根据实体类对象生成SQL语句工具类