C# 写XML例子,根据行政代码树生成XML
2008-01-03 22:50
393 查看
Db_Class DbClass;
XmlTextWriter tw;
//填充一个子项
private void FillOneXml(string Sqlstr, int leveled)
{
int num = Convert.ToInt16(DbClass.Db_Executequery("select count(*) from (" + Sqlstr + ")"));
if (num < 1) return;
OracleDataReader DataReader = DbClass.Db_CreateReader(Sqlstr);
try
{
while (DataReader.Read())
{
string objid = DataReader[0].ToString();
string objName = (string)DataReader[1];
tw.WriteStartElement("cantoncode" + leveled);
tw.WriteAttributeString("cantoncode", objid);
tw.WriteAttributeString("cantonname", objName);
Sqlstr = " Select cantoncode,cantonName from nc_cantoncode "+ " where parentcode =" + objid + " order by cantoncode";
FillOneXml(Sqlstr, leveled + 1);
tw.WriteEndElement();
}
}
finally
{
DataReader.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
DbClass = new Db_Class();
DbClass.Db_Conn();
try
{
string fileName = @"C:/cantoncode.xml";
tw = new XmlTextWriter(fileName, null);
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("cantoncode");
string Sqlstr = " Select cantoncode,cantonName from nc_cantoncode "
+ " where parentcode is null order by cantoncode ";
FillOneXml(Sqlstr, 1);
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
}
finally
{
DbClass.close();
}
}
//测试 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2006.10.11
XmlTextWriter tw;
//填充一个子项
private void FillOneXml(string Sqlstr, int leveled)
{
int num = Convert.ToInt16(DbClass.Db_Executequery("select count(*) from (" + Sqlstr + ")"));
if (num < 1) return;
OracleDataReader DataReader = DbClass.Db_CreateReader(Sqlstr);
try
{
while (DataReader.Read())
{
string objid = DataReader[0].ToString();
string objName = (string)DataReader[1];
tw.WriteStartElement("cantoncode" + leveled);
tw.WriteAttributeString("cantoncode", objid);
tw.WriteAttributeString("cantonname", objName);
Sqlstr = " Select cantoncode,cantonName from nc_cantoncode "+ " where parentcode =" + objid + " order by cantoncode";
FillOneXml(Sqlstr, leveled + 1);
tw.WriteEndElement();
}
}
finally
{
DataReader.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
DbClass = new Db_Class();
DbClass.Db_Conn();
try
{
string fileName = @"C:/cantoncode.xml";
tw = new XmlTextWriter(fileName, null);
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("cantoncode");
string Sqlstr = " Select cantoncode,cantonName from nc_cantoncode "
+ " where parentcode is null order by cantoncode ";
FillOneXml(Sqlstr, 1);
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
}
finally
{
DbClass.close();
}
}
//测试 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2006.10.11
相关文章推荐
- C# 写XML例子--根据行政代码树生成XML
- 根据xsd生成xml文档的c#实现(转)
- 根据xsd生成xml文档的c#实现(转)
- C#根据xsd生成xml
- 根据XML文件生成XSD文件
- c#操作xml的完整例子
- C#生成XML的三种途径
- C#导出生成excel文件方法(xml,html方式)
- C#生成XML的三种途径
- ASP.NET C#上传图片时,根据选中的内容生成缩略图
- C# 根据Word模版生成Word文件
- C#根据WORD模板生成WORD文档 C#网页打印
- 根据powerdesigner的OO模型生成C#代码
- c#生成随机彩色验证码例子
- 第100篇博文纪念 | C# 根据数据库表结构生成DOC数据库文档(3)
- XmlSerializer.Deserialize 方法 (XmlReader)的C#例子
- 根据html页面模板动态生成html页面(c#类)
- C# XML操作类2:xmlHelper例子
- C# 根据Word 模板生成word 文件
- C#开发之生成XmlDocument用来返回错误提示信息