动态修改Web.sitemap


我希望能够在Global.asax中动态的修改Web.sitemap文件,它虽然是XML但是与普通的XML的操作方式还是不一样的。

示例代码如下:

	string xmlPath = Server.MapPath("Web.sitemap");
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlPath);

        XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDoc.NameTable);
        nsMgr.AddNamespace("sm", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
        
        XmlNode root = xmlDoc.SelectSingleNode("//sm:siteMap",nsMgr);
        XmlElement xele = xmlDoc.CreateElement("siteMapNode");
        XmlElement xelesub1 = xmlDoc.CreateElement("siteMapNode");

说明:

If the XML document defines namespaces then you need to use your XmlNamespaceManager to bind prefixes to those namespaces and then you need to use those prefixes in your XPath expressions and you need to pass the XmlNamespaceManager instance as the second argument to the SelectNodes or SelectSingleNode call

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值