I can add a new child "CharacterDevelopmentID" with an incremental ID as innertext to "Characterdevelpments" - no problem. This gets me:
<S2SProject>
<CharacterDevelopments>
<CharacterDevelopmentID>1</CharacterDevelopmentID>
<CharacterDevelopmentID>2</CharacterDevelopmentID>
</CharacterDevelopments>
</S2SProject>
Upon the adding of the CharacterDevelopmentID I need to add an additional child "CharacterDevelopmentName", but only to the CharacterDevelopmentID that was just created so the new XML should look like this:
<S2SProject>
<CharacterDevelopments>
<CharacterDevelopmentID>1
<CharacterDevelopmentName>another test</CharacterDevelopmentName>
</CharacterDevelopmentID>
<CharacterDevelopmentID>2
<CharacterDevelopmentName>yet another test</CharacterDevelopmentName>
</CharacterDevelopmentID>
</CharacterDevelopments>
</S2SProject>
I can't figure out how to select the node programatically. Whenever I try to select the node based on the ID nr nothing happens
fullPath = TSProjectProjectLocation.Text & "\" & TSProjectProjectName.Text
xmlDoc.Load(fullPath)
Dim elemList As XmlNodeList = xmlDoc.GetElementsByTagName("CharacterDevelopmentID")
Dim i As Integer = elemList.Count + 1
newChild = CType(xmlDoc.CreateNode(Xml.XmlNodeType.Element, "CharacterDevelopment", ""), XmlElement)
newChild.SetAttribute("CharacterDevelopmentID", i)
childnode = xmlDoc.CreateElement("CharacterDevelopmentID", i)
Dim elem1 As XmlElement
elem1 = xmlDoc.CreateElement("CharacterDevelopmentID")
elem1.InnerText = i
parNode = xmlDoc.SelectSingleNode("/S2SProject/CharacterDevelopments")
parNode.AppendChild(elem1)
xmlDoc.Save(fullPath) ' --- up to here it works!
elem1 = xmlDoc.CreateElement("CharacterDevelopmentName")
elem1.InnerText = NewCharacterDevelopmentName
parNode = xmlDoc.SelectSingleNode("/S2SProject/CharacterDevelopments/CharacterDevelopmentID[last()]/]") '-- this gives an error XpathException
parNode.AppendChild(elem1)
xmlDoc.Save(fullPath)
I have tried a number of things to get the program to select the right node, but to no avail. Can anyone point me in the right direction? Anything that helps me figure this out would be most appreciated!
I'm getting ready to leave work but I'll leave some code to get you thinking.