Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Is there anyway to add a node to a node list when dealing with XML? I am using c

ID: 3829190 • Letter: I

Question

Is there anyway to add a node to a node list when dealing with XML? I am using c#

I have:

XmlDocument myXML = new XmlDocument();
XmlDataProvider xmlDP = (XmlDataProvider)FindResource("XDP");
myXML.Load("GameData.xml");
xmlDP.Document = myXML;

XmlNodeList abilities = xmlDP.Document.GetElementsByTagName("Abilities");
XmlNode ability = xmlDP.Document.CreateElement("Ability");
XmlNode displayName = xmlDP.Document.CreateElement("DisplayName");
XmlNode flavorText = xmlDP.Document.CreateElement("FlavorText");
XmlNode scriptID = xmlDP.Document.CreateElement("ScriptID");

ability.Attributes["ID"].Value = abilityIDTextBox2.Text;
displayName.InnerText = abilityNameTextBox2.Text;
flavorText.InnerText = flavorTextBox2.Text;
scriptID.InnerText = scriptIDTextBox2.Text;
ability.AppendChild(displayName);
ability.AppendChild(flavorText);
ability.AppendChild(scriptID);

I want to be able to add the ability node to the abilities node list. Can anyone help?

Explanation / Answer

syntax:

creating child node

adding node to the list

ability.ParentNode.AppendChild(displayName);

// ability - is the object of list or parent node means it is correct.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote