分类: C/C++
2008-08-04 09:36:56
struct xmlnode { CString name;//标签名 CString value;//内容 int id;//这个标签的层次,通过栈实现 }; xmlnode node[1000];解析函数:
void str2array(CString context) { CString firstname; CString nextname; CString tempname; CString tempvalue; CStringArray stack;//一个记录标签是否关闭的栈 stack.Add(""); int max=0; int nid=1; int k=0; int i1,i2,j1,j2,k1,k2; while((k附言:'')) { k ; } k1=k; while((k '')) { k ; } j1=k; firstname=getcontext(context,i1,k1);//获得第一个标签 while((k '')) { k ; } k2=k; while((k '')) { k ; } j2=k; nextname=getcontext(context,i2,k2);//获得第二个标签 tempname=''/'' firstname; while(k '')) { k ; } k2=k; while((k '')) { k ; } j2=k; nextname=getcontext(context,i2,k2); if(nextname.Compare(stack.GetAt(max))==0) { stack.RemoveAt(max); nid--; max--; } }while((nextname.GetLength()>0)&&(nextname[0]==''/'')); //same } else//标签没有关闭,压栈 { tempname=''/'' firstname; max ; stack.Add(tempname); node[count].name=firstname; node[count].value=""; node[count].id=nid; count ; nid ; //different } firstname=nextname; i1=i2; k1=k2; j1=j2; while((k '')) { k ; } k2=k; while((k '')) { k ; } j2=k; nextname=getcontext(context,i2,k2); tempname=''/'' firstname; } }