Parsing web.config with XmlDocument.SelectSingleNode
来源:互联网 发布:vb循环语句 for next 编辑:程序博客网 时间:2024/06/14 04:08
问题现象:
I have an utility that modified ASP.NET web.config using code like this:
XmlDocument document = new XmlDocument();
document.Load(sConfigFileName);
XmlNode nodeParent = document.SelectSingleNode("/configuration/system.web");
I found that this code doesn't work with VS 2005 (SelectSingleNode returns null) because configuration element has xmlns
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> .
I was able to delete xmlns attribute without any visible side effects to make SelectSingleNode("/configuration/system.web") working .
But it will be probably required to use new classes in Configuration namespace or use XmlNamespaceManager.
解决方案:
XmlDocument document = new XmlDocument();
document.Load(sConfigFileName);
XmlNamespaceManager ns = new XmlNamespaceManager(document.NameTable);
ns.AddNamespace("x", "http://schemas.microsoft.com/.NetConfiguration/v2.0");
XmlNode myNode = document.SelectSingleNode("/x:configuration/x:system.web",ns);
试过可行
原文地址:http://geekswithblogs.net/mnf/archive/2006/02/02/67909.aspx
- Parsing web.config with XmlDocument.SelectSingleNode
- Connection with Web.config
- 为FireFox的XMLDocument 增加 LoadXML,SelectNodes,SelectSingleNode方法
- C#操作XML文档(XmlDocument、XmlNode、XmlAttribute、SelectSingleNode、SelectNodes、XmlNodeList)
- C#操作XML文档(XmlDocument、XmlNode、XmlAttribute、SelectSingleNode、SelectNodes、XmlNodeList)
- C#操作XML文档(XmlDocument、XmlNode、XmlAttribute、SelectSingleNode、SelectNodes、XmlNodeList)
- C#操作XML文档(XmlDocument、XmlNode、XmlAttribute、SelectSingleNode、SelectNodes、XmlNodeList)
- Parsing JSON With SBJSON
- Parsing Strings with split
- Parsing Arguments with getopt
- ERROR - Parsing error processing resource path /WEB-INF/struts-config.xml解决办法
- javax.servlet.UnavailableException: Parsing error processing resource path /WEB-INF/struts-config.xml
- Parsing error processing resource path /WEB-INF/struts-config.xml解决办法
- Parsing error processing resource path /WEB-INF/struts/struts-config.xml java.io.FileNotFoundException
- javax.servlet.UnavailableException: Parsing error processing resource path /WEB-INF/struts-config.xm
- Android: Simplified source code for parsing and working with XML data and web services in Android
- ASP.NET - Web.Config - Using the tag with web.config can be helpful.
- Parsing URLs with the DOM
- Ubuntu把开机速度提高到3秒的小技巧 (提示 : 我本人并没有实验)
- 窗口子类化和超类化
- 作业
- Windows 窗口子类化和超类化
- 调用控制台程序,并实施获取控制台输出文字
- Parsing web.config with XmlDocument.SelectSingleNode
- 日期常用类总结
- git windows下搭建全过程
- 贝叶斯网络中的推理引擎及其改进参考文献
- Apple iOS MDM开发流程
- poj 2096 Collecting Bugs(概率DP)
- ListCtrl如何响应滚动条事件
- E7
- 2.2,E2(b)