aspnet 操作xml
rr.config
<?xml version="1.0" encoding="utf-8"?>
<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage="index.aspx" defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<add name="content" virtualUrl="^http\://(.*)/(.*)-(\d+).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Default.aspx?templet=$2&id=$3&page=$3" rewrite="Domain" ignoreCase="true" />
</rewrites>
</urlrewritingnet>
string xmlfile = Server.MapPath("~/Config/rr.config");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlfile); //加载文件
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("rewrites");
为什么 xmldocSelect 是null 就是无法读出节点
------解决方案--------------------
是namespace的问题.
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace("xx","http://www.urlrewriting.net/schemas/config/2006/07");
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("//xx:rewrites",xnm);
------解决方案--------------------
//直接找目标节点.可以跳过中间节点.
/开头是指从根节点开始找,但要写完整的路径.