dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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.
    parentNode.AppendChild(xmlEl)
    ' Return the new node to the caller
    Return xmlEl
End Function


' Example: 

' load a XML file
Dim xmldoc As New XmlDocument()
xmldoc.Load("Employees.xml")

' create new Employee element and set its attributes
Dim xmlEl As XmlElement = CreateAppendElement(xmldoc.DocumentElement, _
    "Employee")
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.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date