使用VB.net 2008编写XML的好例子 [英] Whats a Good Example to Write XML using VB.net 2008
本文介绍了使用VB.net 2008编写XML的好例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此示例,我将如何使用此示例更新XML文件:
Using this example how would I go about updating an XML file using this example:
<foo>
<n1>
<s1></s1>
<s2></s2>
<s3></s3>
</n1>
<n1>
<s1></s1>
<s2></s2>
<s3></s3>
</n1>
</foo>
我可以整天阅读它,但是对于我一生来说,我似乎无法将其写成这种格式.
I Can read from it all day long but for the life of me I cannot seem to write it back into that format.
推荐答案
直接方法:
' to create the XmlDocument... '
Dim xmlDoc As New Xml.XmlDocument
Dim fooElement As Xml.XmlElement = xmlDoc.CreateElement("foo")
xmlDoc.AppendChild(fooElement)
Dim n1Element As Xml.XmlElement = xmlDoc.CreateElement("n1")
For Each n1ChildName As String In New String() {"s1", "s2", "s3"}
Dim childElement As Xml.XmlElement = xmlDoc.CreateElement(n1ChildName)
n1Element.AppendChild(childElement)
Next
fooElement.AppendChild(n1Element)
fooElement.AppendChild(n1Element.CloneNode(deep:=True))
' to update the XmlDocument (simple example)... '
Dim s1Element As Xml.XmlElement = xmlDoc.SelectSingleNode("foo/n1/s1")
If Not s1Element Is Nothing Then s1Element.InnerText = "some value"
这篇关于使用VB.net 2008编写XML的好例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文