
请问.net自动生成XML文件代码怎么写?可以我写一下么?
我的代码是这样的,想加多一个pic就对不上,麻烦帮我改正像图片生成的一样。publicvoidProcessRequest(HttpContextcontext){con...
我的代码是这样的,想加多一个pic就对不上,麻烦帮我改正像图片生成的一样。
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/xml";
//context.Response.Write("Hello World");
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(@"D:\Project\Cubilose\imgList.xml");
System.Xml.XmlNode root = xmlDoc.SelectSingleNode("imgList");//查找<imgList>
System.Xml.XmlNode xe1 = xmlDoc.CreateElement("pic");//创建一个<pic>节点
root.AppendChild(xe1);
System.Xml.XmlElement xesub1 = xmlDoc.CreateElement("list");
//xesub1.InnerText = "http://www.zcool.com.cn/u/257071/";//设置文本节点
//xe1.AppendChild(xesub1);//添加到<book>节点中
xesub1.SetAttribute("path", "swf/swf_img/big-185644.jpg");//设置该节点path属性
xesub1.SetAttribute("smallpath", "swf/swf_img/small-185651.png");//设置该节点smallpath属性
xesub1.SetAttribute("smallinfo", "ideacentre Qa系列");//设置该节点smallinfo属性
xe1.AppendChild(xesub1);//添加到<book>节点中
System.Xml.XmlElement xesub2 = xmlDoc.CreateElement("title");
xesub2.InnerText = "http://www.zcool.com.cn/u/257071/";//设置文本节点
xesub1.AppendChild(xesub2);//添加到<book>节点中
xe1.AppendChild(xesub1);//添加到<imgList>节点中
xmlDoc.Save(@"D:\Project\Cubilose\imgList.xml");
} 展开
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/xml";
//context.Response.Write("Hello World");
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(@"D:\Project\Cubilose\imgList.xml");
System.Xml.XmlNode root = xmlDoc.SelectSingleNode("imgList");//查找<imgList>
System.Xml.XmlNode xe1 = xmlDoc.CreateElement("pic");//创建一个<pic>节点
root.AppendChild(xe1);
System.Xml.XmlElement xesub1 = xmlDoc.CreateElement("list");
//xesub1.InnerText = "http://www.zcool.com.cn/u/257071/";//设置文本节点
//xe1.AppendChild(xesub1);//添加到<book>节点中
xesub1.SetAttribute("path", "swf/swf_img/big-185644.jpg");//设置该节点path属性
xesub1.SetAttribute("smallpath", "swf/swf_img/small-185651.png");//设置该节点smallpath属性
xesub1.SetAttribute("smallinfo", "ideacentre Qa系列");//设置该节点smallinfo属性
xe1.AppendChild(xesub1);//添加到<book>节点中
System.Xml.XmlElement xesub2 = xmlDoc.CreateElement("title");
xesub2.InnerText = "http://www.zcool.com.cn/u/257071/";//设置文本节点
xesub1.AppendChild(xesub2);//添加到<book>节点中
xe1.AppendChild(xesub1);//添加到<imgList>节点中
xmlDoc.Save(@"D:\Project\Cubilose\imgList.xml");
} 展开
2个回答
展开全部
不要自己去操作xml节点了,多累呀..
.Net早就有了Xml序列化的类,你构造好实体后,直接序列化一个文件就行了.
System.Xml.Serialization.XmlSerializer建议你去研究下
.Net早就有了Xml序列化的类,你构造好实体后,直接序列化一个文件就行了.
System.Xml.Serialization.XmlSerializer建议你去研究下
更多追问追答
追问
偶是菜鸟加新手。学习中.
追答
就是初学者,才应该多采用微软封装好的类库和功能..等以后经验丰富后,再考虑底层的技术
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询