Create new node from selected node : DOM « XML « VB.Net






Create new node from selected node

  

Public Class Example7
    Shared Sub Main
        Dim doc As System.Xml.XmlDocument
        Dim editor As System.Xml.XPath.XPathNavigator
        Dim writer As System.Xml.XmlWriter

        doc = New System.Xml.XmlDocument()
        doc.Load("pubs.xml")
        editor = doc.CreateNavigator.SelectSingleNode("/pubs")
        writer = editor.AppendChild()
        writer.WriteStartElement("publishers")
        writer.WriteAttributeString("pub_id", "1234")
        writer.WriteAttributeString("pub_name", "new name")
        writer.WriteEndElement()
        writer.Close()
        doc.Save("output.xml")
    End Sub
End Class

   
    
  








Related examples in the same category

1.Get Elements By Tag Name and Loop through NodesGet Elements By Tag Name and Loop through Nodes
2.Read Xml with XmlDocument and XmlNodeReader