我正在试图弄清楚如何选择当前所选xml节点的最后一个子节点。我有点麻烦。
xml文档就像这样开始
<project>
<book>
...
</book>
<characters>
<character>
.....
</character>
</characters>
</project>
我需要能够在字符内附加一个新的字符元素以及内部的子节点和数据。
如果存在字符节点,我就使用了if else语句,如果不存在。我正在研究它现在是否存在。基本上,文档已经包含一个字符。
这是我正在使用的代码。
nav = nav.SelectSingleNode("/project/characters")
nav.AppendChildElement("", "character", "", "")
nav.SelectSingleNode("//project/characters/*[last()]")
nav.AppendChildElement("", "name", "", characterName)
nav.AppendChildElement("", "race", "", characterRace)
nav.AppendChildElement("", "age", "", characterAge)
nav.AppendChildElement("", "name", "", characterName)
nav.AppendChildElement("", "race", "", characterRace)
nav.AppendChildElement("", "age", "", characterAge)
nav.AppendChildElement("", "gender", "", characterGender)
nav.AppendChildElement("", "origin", "", characterOrigin)
nav.AppendChildElement("", "eye", "", characterEyeColor)
nav.AppendChildElement("", "hair", "", characterHairColor)
nav.AppendChildElement("", "weight", "", characterWeight)
nav.AppendChildElement("", "height", "", characterHeight)
nav.AppendChildElement("", "occupation", "", characterOccupation)
nav.AppendChildElement("", "birthmarks", "", characterBirthmarks)
nav.AppendChildElement("", "piercings", "", characterPiercings)
nav.AppendChildElement("", "tattoos", "", characterTattoos)
nav.AppendChildElement("", "scars", "", characterScars)
Do While counter < traitCount
nav.AppendChildElement("", "trait", "", characterTraits.AsReadOnly(counter))
counter = counter + 1
Loop
counter = 0
Do While counter < habitCount
nav.AppendChildElement("", "habit", "", characterHabits.AsReadOnly(counter))
counter = counter + 1
Loop
nav.AppendChildElement("", "bio", "", characterBio)
document.Save(ProjectDataMod.projectPathMod + ProjectDataMod.projectNameMod + ".xml")
非常感谢任何帮助。谢谢你的时间。
JB。