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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.