How to get specific fields in child nodes of an XML file given a node
hey, gang:
this simple question, , used know answer, i'm tired , can't remember how , numerous google searches aren't turning need.
i've got xml file:
<?xml version="1.0" encoding="utf-8"?> <army> <armyname>the army of northern virginia</armyname> <commander> <commandername>the emperor napoleon</commandername> <commanderleadership>94</commanderleadership> <division> <divisioncommandername>major general william t. sherman</divisioncommandername> <divisioncommanderleadership>78</divisioncommanderleadership> <unit> <unitname>chasseurs à cheval garde</unitname> <uniticon>cavalry.png</uniticon> <unittype>cavalry</unittype> <unitkstrength>3</unitkstrength> <unitstrength>456</unitstrength> <unitquality>94</unitquality> <unitmorale>72</unitmorale> <unitleadership>74</unitleadership> <unitammunition>99</unitammunition> </unit> <unit> <unitname>battery b 4th artillery</unitname> <uniticon>artillery.png</uniticon> <unittype>artillery</unittype> <unitkstrength>3</unitkstrength> <unitstrength>4456</unitstrength> <unitquality>88</unitquality> <unitmorale>65</unitmorale> <unitleadership>82</unitleadership> <unitammunition>25</unitammunition> </unit> </division> <division> <divisioncommandername>spoons butler</divisioncommandername> <divisioncommanderleadership>18</divisioncommanderleadership> <unit> <unitname>2nd wisconsin infantry</unitname> <uniticon>infantry.png</uniticon> <unittype>infantry</unittype> <unitkstrength>3</unitkstrength> <unitstrength>1456</unitstrength> <unitquality>92</unitquality> <unitmorale>48</unitmorale> <unitleadership>87</unitleadership> <unitammunition>25</unitammunition> </unit> <unit> <unitname>3rd brigade supply train</unitname> <uniticon>supplies.png</uniticon> <unittype>supply</unittype> <unitkstrength>3</unitkstrength> <unitstrength>4256</unitstrength> <unitquality>32</unitquality> <unitmorale>36</unitmorale> <unitleadership>25</unitleadership> <unitammunition>3</unitammunition> </unit> </division> <division> <divisioncommandername>advanced guard</divisioncommandername> <divisioncommanderleadership>86</divisioncommanderleadership> <unit> <unitname>27ème régiment d'lnfanterie légère</unitname> <uniticon>lightinfantry.png</uniticon> <unittype>light infantry</unittype> <unitkstrength>2</unitkstrength> <unitstrength>1256</unitstrength> <unitquality>82</unitquality> <unitmorale>56</unitmorale> <unitleadership>75</unitleadership> <unitammunition>23</unitammunition> </unit> </division> <division> <divisioncommandername>general of division olivier rivaud de la raffinière</divisioncommandername> <divisioncommanderleadership>76</divisioncommanderleadership> <unit> <unitname>8ème régiment d'lnfanterie de ligne</unitname> <uniticon>infantry.png</uniticon> <unittype>infantry</unittype> <unitkstrength>2</unitkstrength> <unitstrength>1256</unitstrength> <unitquality>94</unitquality> <unitmorale>78</unitmorale> <unitleadership>72</unitleadership> <unitammunition>23</unitammunition> </unit> <unit> <unitname>45ème régiment d'lnfanterie de ligne</unitname> <uniticon>infantry.png</uniticon> <unittype>infantry</unittype> <unitkstrength>2</unitkstrength> <unitstrength>1256</unitstrength> <unitquality>94</unitquality> <unitmorale>78</unitmorale> <unitleadership>72</unitleadership> <unitammunition>23</unitammunition> </unit> <unit> <unitname>54ème régiment d'lnfanterie de ligne</unitname> <uniticon>infantry.png</uniticon> <unittype>infantry</unittype> <unitkstrength>2</unitkstrength> <unitstrength>1256</unitstrength> <unitquality>94</unitquality> <unitmorale>78</unitmorale> <unitleadership>72</unitleadership> <unitammunition>23</unitammunition> </unit> <unit> <unitname>2ème régiment de hussards</unitname> <uniticon>lightcavalry.png</uniticon> <unittype>light cavalry</unittype> <unitkstrength>2</unitkstrength> <unitstrength>1256</unitstrength> <unitquality>94</unitquality> <unitmorale>78</unitmorale> <unitleadership>72</unitleadership> <unitammunition>99</unitammunition> </unit> </division> </commander> </army>
given node:
xmlnode selectednode;
how can return values in field "unitname" children of selectednode?
i got run using this:
xmlnodelist nodes = mainwindow.selectednode.selectnodes(".//unitname"); foreach (xmlnode unitname in nodes) { messagebox.show("you delete following units: " + unitname.innertext); }
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment