获取XML节点内容的问题?

nanfei01055 2008-12-29 11:14:48
请问如何能获取appSettings的整个节点的内容?
Dim configPath As String = Server.MapPath("web.config")
Dim doc As XmlDocument = New XmlDocument()
doc.PreserveWhitespace = True
doc.Load(configPath)
Dim appSettingsXmlNode As XmlNode
appSettingsXmlNode = doc.DocumentElement.SelectSingleNode("//appSettings")
AppSettingsEncrypted.Text = Chr(13) & Chr(10) & appSettingsXmlNode.OuterXml
'这句提示"未将对象引用到实例"


Web.config内容如下:

<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="currencyService" value="http://www.microsoft.com/services/currencyService.asmx"/>
<add key="creditCardValidationService" value="http://www.microsoft.com/services/cc.asmx"/>
</appSettings>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>
-->
</system.web>
</configuration>
...全文
113 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
t397123215 2011-07-11
  • 打赏
  • 举报
回复
能不能根据节点名称直接读取呢?
nanfei01055 2008-12-29
  • 打赏
  • 举报
回复
好了,还是自己遍历吧,没有人,分就给上面两位吧
nanfei01055 2008-12-29
  • 打赏
  • 举报
回复
我的问题是要一次性读出appSettins节点下的所有内容,以文本的形式呈现出来,有没有更好的建议,因为XmlNodeList 没有一个类似OuterText的方法,输出整个节点的内容,还请高手支招.
nanfei01055 2008-12-29
  • 打赏
  • 举报
回复
我的问题是要一次性读出appSettins节点下的所有内容,以文本的形式呈现出来,有没有更好的建议,因为XmlNodeList 没有一个类似OuterText的方法,输出整个节点的内容,还请高手支招.
chuxue1342 2008-12-29
  • 打赏
  • 举报
回复
试下一楼的~
zhuanshen712 2008-12-29
  • 打赏
  • 举报
回复
获取appSettings的整个节点的内容:
XmlNodeList a=doc.DocumentElement.GetElementsByTagName("appSettings");
得到一个appsetting的字节点集合。

16,556

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧