The way to add XElement
as child of another XElement
is simply call .Add()
in the parent element passing child element as parameter. You already done that with <name>
and <category>
element here :
oEmp.Add(New XElement("name", 3))
oEmp.Add(New XElement("category", 3))
So it should be the same for <source>
element :
Dim src As New XElement("source")
src.Add(New XAttribute("id", 3))
src.Add(New XElement("category", 3))
oEmp.Add(src)
Another thing, your code doesn't use oEmp
element created in the end. If I understand what you're after correctly, you should add it as child of the root element (<projects>
) this way before saving doc
:
Dim root = doc.Root;
root.Add(oEmp);