加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

什么是使用VB.net 2008编写XML的好例子

发布时间:2020-12-17 00:08:18 所属栏目:大数据 来源:网络整理
导读:使用此示例,我将如何使用此示例更新 XML文件: foo n1 s1/s1 s2/s2 s3/s3 /n1 n1 s1/s1 s2/s2 s3/s3 /n1/foo 我可以整天读它,但对于我的生活,我似乎无法把它写回那种格式. 直截了当的方法: ' to create the XmlDocument... 'Dim xmlDoc As New Xml.XmlDocum
使用此示例,我将如何使用此示例更新 XML文件:
<foo>
   <n1>
       <s1></s1>
       <s2></s2>
       <s3></s3>
   </n1>
   <n1>
       <s1></s1>
       <s2></s2>
       <s3></s3>
   </n1>
</foo>

我可以整天读它,但对于我的生活,我似乎无法把它写回那种格式.

直截了当的方法:
' 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"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读