日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

手动生成 XML

發布時間:2023/12/10 asp.net 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 手动生成 XML 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

private void Button1_Click(object sender, System.EventArgs e)
{
//創建新的xml
XmlDocument doc = new XmlDocument();
doc.LoadXml("<company></company>");
//設置版本信息
XmlDeclaration xmldecl;
xmldecl = doc.CreateXmlDeclaration("1.0",null,null);
xmldecl.Encoding="gb2312";
//xmldecl.Standalone="yes";

//
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 ;
}

轉載于:https://my.oschina.net/u/225383/blog/49900

總結

以上是生活随笔為你收集整理的手动生成 XML的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。