<?xml version="1.0" encoding="utf-8" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.example.com/sitemap1.xml.gz</loc>
<lastmod>2004-10-01T18:23:17+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.example.com/sitemap2.xml.gz</loc>
<lastmod>2005-01-01</lastmod>
</sitemap>
</sitemapindex>public static void XmlInsertElement(string xmlPath, string MainNode, string Element, string Content)
{
XmlDocument objXmlDoc = new XmlDocument();
objXmlDoc.Load(xmlPath);
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.InnerText = Content;
objNode.AppendChild(objElement);
objXmlDoc.Save(xmlPath);
}调用 XmlInsertElement("xxx.xml","sitemapindex","sitemap","");
XmlInsertElement("xxx.xml","sitemapindex/sitemap","loc","www.baidu.com");
XmlInsertElement("xxx.xml","sitemapindex/sitemap","lastmod","2012-11-11");谁帮我改进下XmlInsertElement这个方法,能一次增加sitemap和下面多个子节点+值
注意:创建的时候 loc、lastmod不要跑到别的sitemap节点下
求解,要代码.谢谢~
解决方案 »
- .net发邮件控件
- Ajax修改数据的困惑
- 一个菜鸟问题,麻烦高手指点!(实在没有分了,望高手免费指点一下)
- 数据库更新的问题
- 请问本站何处有ASP.NET的从基础到精通一类教程?
- 求解一个会员注册程序中的部分函数的使用问题
- 请问非法字符串的正则表达式怎么写?比如一个字符串中不能包含“&”,"$"
- 用JavaScript实现为FreeTextBox中添加字符
- 斑竹看看这个错误,怎么常常遇到!(是不是CSDN的bug)
- config.web文件哪去了??
- asp.net控件在设计的时候显示错误,运行却没问题
- C# xml修改删除节点 ..............................................新手求解、在线等
doc.LoadXml(xml); XmlNodeList nodeList = doc.DocumentElement.ChildNodes;
XmlElement newNode = null;
foreach (XmlNode node in nodeList)
{
if (node.Name == "")
{
foreach (XmlNode li in node.ChildNodes)
{
if (li.Name == "")
{
string s = li.Attributes[""].Value; newNode = doc.CreateElement("x");
newNode.SetAttribute("xx", "");
node.InsertAfter(newNode, li);
}
}
}
}
public static void XmlInsertElement(string xmlPath, string locValue, string lastmod)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlPath); XmlElement node = xmlDoc.CreateElement("sitemap"); XmlElement locNode= xmlDoc.CreateElement("loc");
locNode.InnerText=locValue;
node.AppendChild(locNode); XmlElement lastmodNode = xmlDoc.CreateElement("lastmod");
lastmodNode.InnerText = lastmod;
node.AppendChild(lastmodNode); xmlDoc.DocumentElement.AppendChild(node);
xmlDoc.Save(xmlPath);
} // XmlInsertElement("..\\..\\test2.xml", "aasdfg", "123456");