请问这样的XML节点该如何读取?
myConfigFile.xml
<Root>
<MyConfig>
<My.Settings>
<setting name="Text1">
<value>this is a test1</value>
</setting>
<setting name ="Text2">
<value>this is a test2</value>
</setting>
<setting name ="Text3">
<value>this is a test3</value>
</setting>
</My.Settings>
</MyConfig>
</Root>
希望能够读写
1。我尝试用下面的代码读取My.Settings节点,可是取出的是Nothing
Dim doc As XmlDocument = New XmlDocument
doc.Load(myConfigFile)
Dim node As XmlNode = doc.SelectSingleNode("Root/MyConfig/My.Settings")
2。如何读写name ="Text2"的setting节点的值呢?
比如,我想把其value值"this is a test2"修改为 "this is a my test"
[解决办法]
Dim doc As XmlDocument = New XmlDocument
doc.Load("L:\mvc2\WindowsApplication1\myConfigFile.xml")
Dim node As XmlNode = doc.SelectSingleNode("/Root/MyConfig/My.Settings")
MessageBox.Show(node.Name)
node = doc.SelectSingleNode("/Root/MyConfig/My.Settings/setting[@name='Text2']/value")
MessageBox.Show(node.InnerText)
node.InnerText = "this is a my test"
doc.Save("L:\mvc2\WindowsApplication1\myConfigFile.xml")
是没有问题 的