【问题标题】:create Xml Document from Node从节点创建 XML 文档
【发布时间】:2016-09-26 18:46:32
【问题描述】:

尝试从传递给方法的现有 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

【问题讨论】:

    标签: asp.net xml vb.net


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 2016-11-05
      • 2020-01-15
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      相关资源
      最近更新 更多