将节点追加到现有xml [英] append node to existing xml

查看:65
本文介绍了将节点追加到现有xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用vb.net窗口应用程序.

这里我有一个xml文件

Hi,

I am working on vb.net Window application.

here i have a xml file

<archivedata>

  <archive>
    <date>1-1-1980</date>
    <name>Archive Name</name>
    <email>someemail@domain.com</email>
    <time>11:40</time>
  </archive>

</archivedata>



我需要务实地补充一下..



i need to append pragmatically like..

<archivedata>

  <archive>
    <date>1-1-1980</date>
    <name>Archive Name</name>
    <email>someemail@domain.com</email>
    <time>11:40</time>
  </archive>

  <archive>
    <date>1-1-1990</date>
    <name>Archive Name</name>
    <email>someemail@domain.com</email>
    <time>09:40</time>
  </archive>
	
  <archive>
    <date>1-1-1999</date>
    <name>Archive Name</name>
    <email>someemail@domain.com</email>
    <time>10:40</time>
  </archive>
   
  .
  .
  .
  and so on...

</archivedata>



有人可以帮我吗?

感谢



can somebody help me?

thanks

推荐答案

此处 [ ^ ]是一个示例使用XMLDocument执行此操作.
Here[^] is an example that does this using XMLDocument.


请尝试以下操作:

Try This:

Dim newArchive As String = _
            "<archive>" & _
            "    <date>1-1-1993</date>" & _
            "    <name>bill</name>" & _
            "    <email>billmail@yahoo.com</email>" & _
            "    <time>1:39</time>" & _
            "  </archive>"
        Dim xmldoc1 As New XmlDocument()
        xmldoc1.Load("test.xml")
        Dim xmldocFragment As XmlDocumentFragment = xmldoc1.CreateDocumentFragment()
        xmldocFragment.InnerXml = newArchive
        Dim XmlNode1 As XmlNode = xmldoc1.DocumentElement
        XmlNode1.AppendChild(xmldocFragment)
        xmldoc1.Save("test.xml")


这篇关于将节点追加到现有xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆