Add the new node to the bottom of the XML tree : XML Edit « XML LINQ « VB.Net






Add the new node to the bottom of the XML tree

    
Imports System
Imports System.Xml.Linq

    Public Class MainClass
        Public Shared Sub Main()
            Dim employees As XElement = XElement.Load("Employees.xml")
            Dim newEmployee = <Employee id=<%= 1 %>>
                                  <Name>First</Name>
                                  <Title>Coder</Title>
                                  <HireDate>07/15/2006</HireDate>
                                  <HourlyRate>9.95</HourlyRate>
                              </Employee>

            employees.Add(newEmployee)

            For Each ele In employees.<Employee>
                ele.Add(<TerminationDate></TerminationDate>)
                ele.Add(New XAttribute("Status", ""))
            Next
            Console.WriteLine(employees.ToString())
        End Sub
    End Class

   
    
    
    
  








Related examples in the same category

1.Remove content from XElement
2.Remove from XElement
3.Remove the 4th Employee element.
4.XElement.RemoveAll Method removes nodes and attributes from this XElement.
5.XElement.RemoveAttributes removes the attributes of this XElement.
6.XElement.SetAttributeValue sets the value of an attribute, adds an attribute, or removes an attribute.
7.XElement.SetElementValue sets the value of a child element, adds a child element, or removes a child element.
8.Listen to Add, Remove events
9.Replace content from XElement
10.XElement.ReplaceAll replaces child nodes and attributes with the specified content.
11.ReplaceAll with an array of XElement objects
12.XElement.ReplaceAll(Object[]) replaces child nodes and attributes with the specified content.
13.XElement.ReplaceAttributes (Object) replaces the attributes with the specified content.
14.XElement.ReplaceAttributes (Object[]) replaces attributes with the specified content.
15.ReplaceAll with a string
16.ReplaceAll with a double
17.ReplaceAll with a DateTime object
18.ReplaceAll with a string array
19.Update attribute for XElement
20.Update XElement
21.Adding XElement to XElement
22.Add 5 new green Fords to the incoming document