//
xmlelement root = doc.documentelement;
doc.insertbefore(xmldecl, root);
//设置根结点
xmlelement newcompany = doc.documentelement;
//创建新的name
xmlelement newname = doc.createelement("name");
newname.innertext = "公司名称"; //公司名称
//加入父结点
newcompany.appendchild(newname);
xmlelement newinfo = doc.createelement("info");
newinfo.innertext = "简介"; //简介
newcompany.appendchild(newinfo);
xmlelement newcontactinfo = doc.createelement("contactinfo");
newcontactinfo.innertext = "网址"; //网址
newcompany.appendchild(newcontactinfo);
xmlelement newcontactperson = doc.createelement("contactperson");
newcontactperson.innertext = "姓名"; //姓名
newcompany.appendchild(newcontactperson);
xmlelement newcontactzip = doc.createelement("contactzip");
newcontactzip.innertext = "邮编"; //邮编
newcompany.appendchild( newcontactzip );
xmlelement newcontactadd = doc.createelement("contactadd");
newcontactadd.innertext = "地址"; //地址
newcompany.appendchild( newcontactadd );
//工作列表
//先创建jobs类表
xmlelement newjobs = doc.createelement("jobs");
newcompany.appendchild( newjobs );
//dataset ds = new dataset();
//if(ds!=null)
//{
//foreach(datarow dr in ds.tables[0].rows)
for(int i=0;i<5;i++)
{
xmlelement newjob = doc.createelement("job");
newjobs.appendchild( newjob );
xmlelement newtitle = doc.createelement("title");
newtitle.innertext = i.tostring(); //职位名称
newjob.appendchild( newtitle );
xmlelement newurl = doc.createelement("url");
newurl.innertext = "http://www.020job.com"; //网址
newjob.appendchild( newurl );
}
//}
//doc.documentelement.appendchild(newcompany);
xmltextwriter tr = new xmltextwriter(server.mappath(random_str()),system.text.encoding.getencoding("gb2312"));
doc.writecontentto(tr);
tr.close();
}
private string random_str()
{
random oran = new system.random();
string filename =
datetime.now.year.tostring() +
datetime.now.month.tostring() +
datetime.now.day.tostring() +
datetime.now.hour.tostring() +
datetime.now.minute.tostring() +
datetime.now.second.tostring() +
oran.next(9999).tostring() +
".xml";
return filename ;
}
新闻热点
疑难解答
图片精选