Suggested method to insert sub-child into child that already exist

Program4Food

Member
Joined
Dec 6, 2021
Messages
16
Programming Experience
5-10
I don't even know if I am using the right terminology because I read some call it node, some call it child... I am
still mudding though XML structure, its far more complex once you dig into it then it appears at first glance.

Anyway, say I have an XML that looks like this: (Root elements removed for clarity)
VB.NET:
  <ItemList>
    <item>camera</item>
    <item>flash</item>
  </ItemList>

and I want it to look like this:

VB.NET:
  <ItemList>
    <item>camera</item>
    <item>flash</item>
    <item>trigger</item>
  </ItemList>

I dont want anyone to write the code for me, just looking for direction.

Everything I have seen was too complex for me to comprehend, and what I could get to work
was making a new <ItemList> instead of inserting it into the one that was already there.

The XML file I will be building and using will have no two elements of the same name (chrildren of the same name?)
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,588
Location
Norway
Programming Experience
10+
Let's say you have a reference to the ItemList element:
VB.NET:
element.Add(<item><%= "value" %></item>)
And if you need to add elements with dynamic names at runtime:
VB.NET:
element.Add(New XElement("item", "value"))

By the way, node is like the Object data type in VB, the least specific data type.
 
Top Bottom