Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB7
Expertise: Intermediate
Nov 11, 2002



Building the Right Environment to Support AI, Machine Learning and Deep Learning

CreateAppendElement - appending a XmlElement under another XmlNode

' Create an XmlElement object with inner text and make it a child of another 
' XmlNode.
' Note: requires Imports System.Xml

Function CreateAppendElement(ByVal parentNode As XmlNode, ByVal name As String, _
    Optional ByVal innerText As String = Nothing) As XmlElement
    ' Create a new XmlElement object, set the return value.
    Dim xmlEl As XmlElement = parentNode.OwnerDocument.CreateElement(name)
    ' Set its inner text
    If Not (innerText Is Nothing) Then xmlEl.InnerText = innerText
    ' make it a child of its parent node.
    ' Return the new node to the caller
    Return xmlEl
End Function

' Example: 

' load a XML file
Dim xmldoc As New XmlDocument()

' create new Employee element and set its attributes
Dim xmlEl As XmlElement = CreateAppendElement(xmldoc.DocumentElement, _
xmlEl.SetAttribute("id", "100")
' create sub-elements
CreateAppendElement(xmlEl, "firstName", "Joe")
CreateAppendElement(xmlEl, "lastName", "Doe")

' Note: This code is taken from Francesco Balena's
' "Programming Microsoft Visual Basic .NET" - MS Press 2002, ISBN 0735613753
' You can read a free chapter of the book at 
' http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date