I have an XML file with the following structure...
<Tournament TeamPlayers="1">
<Teams>
<Team>
<TeamID></TeamID>
<Name></Name>
<Status></Status>
<Memo></Memo>
<ByeRounds></ByeRounds>
<Players>
<Player Seat="A">
<MemberNo></MemberNo>
<MemberName></MemberName>
<PlayerFirstName></PlayerFirstName>
<PlayerLastName></PlayerLastName>
</Player>
</Players>
</Team>
</Teams>
<Staff>
<Player>
<MembershipNo></MembershipNo>
<PlayerFirstName></PlayerFirstName>
<PlayerLastName></PlayerLastName>
<MembershipName></MembershipName>
<Position></Position>
</Player>
</Staff>
<Penalties>
<Penalty>
<Judge></Judge>
<Player></Player>
<InfractionType></InfractionType>
<PenaltyType></PenaltyType>
<Notes></Notes>
</Penalty>
</Penalties>
</Tournament>
The idea is that I would iterate through each child node ( Teams
, Staff
, Penalty
) and assign each into a list. I have the following bit of code to start but can't figure out how to go into the nested Players
element and assign it to .tpPlayerA
as part of the New PlayerInfo
construct.
Dim TeamsNodes = xDoc.Descendants("Teams")
lstOutputTeams = team.Descendants("Team").[Select](Function(t) New TournamentTeam With {
.intTeamID = t.Element("TeamID"),
.intByeRounds = t.Element("ByeRounds"),
.strTeamName = t.Element("Name"),
.strMemo = t.Element("Memo"),
.intStatus = t.Element("Status"),
.tpPlayerA = (From p In team.Descendants("Players") Select New PlayerInfo With {
.strMembershipNo = p.Element("MemberNo").Value,
.strPlayerFirstName = p.Element("PlayerFirstName").Value,
.strPlayerLastName = p.Element("PlayerLastName").Value,
.strMembershipName = p.Element("MemberName")})
}).ToList()
Next
lstFinalOutput.Add(lstOutputTeams)
(The above kind of ported from this answer: Nesting LINQ to XML )
However running the above,I get the error "Input string was not in a correct format". What did I get wrong here?
1条答案
按热度按时间bq9c1y661#
我想我错过了什么...但是,