I have a xml file that looks as such
and I want to add a person with the name of "b" but put in inbetween "a" and "z" to keep it alphabetical.
I was able to add to the bottom so it would look like
with this code
So does anyone know how I can modify this to allow me to insert into the middle?
Code:
<people>
<person name="a" id"123">
<person name="z" id"312">
</people>
I was able to add to the bottom so it would look like
Code:
<people>
<person name="a" id"123">
<person name="z" id"312">
<person name="b" id"452">
</people>
Code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xml);
XmlNode node = xmlDoc.SelectSingleNode("/people");
XmlElement el = xmlDoc.CreateElement("person");
el.SetAttribute("name", name);
el.SetAttribute("id", id);
node.AppendChild(el);
xmlDoc.Save(xmlFile);
Comment