c# - Search results xml, c # - Windows Application Store -
good day, creating app bible, i'm having trouble searching verse ("v"). have created whole structure can filter book ("b"), loads list of chapters ("c"), when select chapter, creates list , loads verses. want put code when user clicks on list number, displayed text of verse.
xml
<?xml version="1.0" encoding="utf-8"?> <bible> <b n="gênesis" indice="1"> <c n="1"> <v n="1">text text</v> <v n="2">text text text</v> </c> <c n="2"> <v n="1">text text</v> <v n="2">text text text</v> </c> <b n="Êxodo" indice="2"> <c n="1"> <v n="1">text text</v> <v n="2">text text text</v> </c> <c n="2"> <v n="1">text text</v> <v n="2">text text text</v> </c> </b> </bible>
c#
private void listboxteste1_selectionchanged(object sender, selectionchangedeventargs e) { int selectedindex = listboxteste1.selectedindex; //carregar o arquivo xml xdocument xdoc = xdocument.load("biblia.xml"); var players = player in xdoc.descendants("v") (string)player.attribute("n") == selectedindex.tostring() select new { versiculo = (string)player.element("v") }; //listbox2.itemssource = players; nameinput.text = nameinput.text + " " + players; }
i'm not quite clear on question, since code has errors, assume that's thing need with;
var players = player in xdoc.descendants("c") (string)player.attribute("n") == selectedindex.tostring(cultureinfo.invariantculture) select new { versiculo = player.elements("v").select(x => x.value) }; console.writeline(string.join(", ", players.first().versiculo));
players
return collection of strings (the items inside v
nodes) in versiculo
, , print them out joined ,
.
the thing made return no results you're getting first matching v
node, trying take v
subnodes of result.
Comments
Post a Comment