从Node创建Xml文档

时间:2016-09-26 18:46:32

标签: asp.net xml vb.net

尝试从传递给方法的现有xml节点创建新的xml文档。这与VB.NET。怎么做 ?

Private Shared Sub WriteChanges(parentNode As XmlNode, nodeName As String, m As Model.ModelBaseWithTracking)
    Dim xml As New XmlDocument()
    If parentNode.Name = "#document" Then
         'Need code here 
    End If

End Sub

1 个答案:

答案 0 :(得分:1)

这很简单。您可以在XML文档中创建节点,如下所示:

Private Shared Sub WriteChanges(parentNode As XmlNode, nodeName As String, m As Model.ModelBaseWithTracking)
  Dim xml As New XmlDocument()
  If parentNode.Name = "#document" Then

    //To create root elemet
    Dim root As XmlElement = xml.CreateElement("document")
    xml.AppendChild(root)

    //To add child node to root element
     Dim child As XmlElement = xml.CreateElement("document1")
     root.AppendChild(child)

     child.SetAttribute("id", "1")

     //Add more nodes same as shown above..

  End If
End Sub