asp.net|xml|生成xml|示例|递归
asp.net递归生成XML树的示例
代码:
以下是引用片段:
//CDepartmentInfo 类别实体类
//sjid :与大类别关联ID
//space:只是一个标记
//strOpinion用来存放类名
string sjid = "0";
string space = "+";
string strOpinion = "";
string paths = "E:\test";
string FILE_NAME = paths + "\\BMCategory.XML";
flag = true;
StreamWriter sr = File.CreateText( "BMCategory" );
sr.Close();
StreamWriter x = new StreamWriter( FILE_NAME, true, System.Text.Encoding.Default );
x.Write( "<R>");
Display( sjid, space, ref iCount,x );
x.Write( "</R>" );
x.Close();
递归写入XML涵数... 代码:
以下是引用片段: public void Display( string sjid, string space, ref int iCount,StreamWriter x ) { List<CDepartmentInfo> DepartmentList = new List<CDepartmentInfo>(); DepartmentList = OrganizationRule.GetList( sjid );//读取一个列表类,这里是LIST foreach ( CDepartmentInfo aa in DepartmentList ) { strOpinion = aa.BM_CategoryName.Trim().ToString(); x.Write( "<DSTree"+aa.BM_Categorylxpm.Trim()+" text=\"" + aa.BM_CategoryName.Trim() + "\" treeId=\"" + aa.BM_Categorylxpm.Trim() + "\" mspace=\"栏目管理\">"+ strOpinion ); x.Write( "\r\n" ); Display( aa.BM_Categorylxpm.ToString().Trim(), Text + space, ref iCount,x ); x.Write( "</DSTree" + aa.BM_Categorylxpm.Trim() + ">" ); } |