//
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);dom
XmlElement newContactinfo = doc.CreateElement("contactinfo");
newContactinfo.InnerText = "網址"; //網址
newCompany.AppendChild(newContactinfo);url
XmlElement newContactperson = doc.CreateElement("contactperson");
newContactperson.InnerText = "姓名"; //姓名
newCompany.AppendChild(newContactperson);xml
XmlElement newContactzip = doc.CreateElement("contactzip");
newContactzip.InnerText = "郵編"; //郵編
newCompany.AppendChild( newContactzip );ip
XmlElement newContactadd = doc.CreateElement("contactadd");
newContactadd.InnerText = "地址"; //地址
newCompany.AppendChild( newContactadd );get
//工做列表
//先建立jobs類表string
XmlElement newJobs = doc.CreateElement("jobs");
newCompany.AppendChild( newJobs );it
//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 );io
XmlElement newTitle = doc.CreateElement("title");
newTitle.InnerText = i.ToString(); //職位名稱
newJob.AppendChild( newTitle );object
XmlElement newUrl = doc.CreateElement("url");
newUrl.InnerText = "http://www.020job.com"; //網址
newJob.AppendChild( newUrl );
}
//}foreach
//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 ; }