标题:VB.net XML文件解析修改_求助
只看楼主
a6681316
Rank: 2
等 级:论坛游民
帖 子:21
专家分:27
注 册:2010-12-17
结帖率:71.43%
已结贴  问题点数:20 回复次数:1 
VB.net XML文件解析修改_求助
有这样一个xml
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
  <Bassettings>
   <settingname="A" ser="String">
    <value>0<value>
      </setting>
   <settingname="B" ser="String">
    <value>10000<value>
      </setting>

   </Bassettings>
</appsettings>
</configuration>

如何获取A的value,和B的value,并且修改保存 麻烦大神解决下
搜索更多相关主题的帖子: VB.net XML 文件 修改 value 
2019-02-20 09:45
厨师王德榜
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:183
帖 子:942
专家分:4724
注 册:2013-2-16
得分:20 
程序代码:
    Private Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
        '测试用 获取A的value,和B的value,并且修改保存
        Dim cpath As String = "E:\vbnet.prj\ModifyFileZillaXml\ModifyFileZillaXml\bin\Debug\sets.xml"
        Dim xd As New Xml.XmlDocument
        Dim aValue As String = "", bValue As String = "", cSettingName As String
        xd.Load(cpath)
        For Each nodeSets As Xml.XmlNode In xd.SelectSingleNode("configuration").SelectSingleNode("appsettings").SelectSingleNode("Bassettings")
            cSettingName = nodeSets.Attributes("name").Value
            Select Case cSettingName
                Case "A"
                    aValue = nodeSets.InnerText
                    nodeSets.ChildNodes(0).ChildNodes(0).Value = "99"
                Case "B"
                    bValue = nodeSets.InnerText
                    nodeSets.ChildNodes(0).ChildNodes(0).Value = "999"
            End Select
        Next
        '写到硬盘,释放内存。
        Dim tr As Xml.XmlTextWriter = New Xml.XmlTextWriter(cpath, Nothing) '写XML文件。
        tr.Formatting = Xml.Formatting.Indented
        xd.WriteContentTo(tr)
        tr.Close() '释放内存。
        Debug.Print("setting A.OldValue=" & aValue & ",修改后的值:99")
        Debug.Print("setting B.OldValue=" & bValue & ",修改后的值:999")
    End Sub

运行结果:
setting A.OldValue=0,修改后的值:99
setting B.OldValue=10000,修改后的值:999
2019-02-22 22:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-493132-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022179 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved