c# - ASP.Net VB - Linq to XML group by child element value -


i need group values based on child element value. below example of xml

<matchday date="2016-05-09">    <match id="1288348">       <home id="13" name="club1"/>       <away id="14" name="club2"/>       <information>          <country>england</country>       </information>    </match>    <match id="1288349">       <home id="15" name="club3"/>       <away id="16" name="club4"/>       <information>          <country>england</country>       </information>    </match>    <match id="1288350">       <home id="17" name="club5"/>       <away id="18" name="club6"/>       <information>          <country>italy</country>       </information>    </match>    <match id="1288351">       <home id="19" name="club7"/>       <away id="20" name="club8"/>       <information>          <country>spain</country>       </information>    </match> </matchday> 

i want group country, result :

england    1288348    1288349  italy    1288350  spain    1288351 

how using vb linq xml query code-behind.

thanks

this 1 possible way :

dim result = data.elements("match") _                  .groupby(function(x) x.element("information").element("country").value)  each r igrouping(of string, xelement) in result     console.writeline(r.key)     each m xelement in r         console.writeline(m.@id)     next next 

where data xelement declared follow :

dim data xelement = <matchday date="2016-05-09">                        <match id="1288348">                            <home id="13" name="club1"/>                            <away id="14" name="club2"/>                            <information>                                <country>england</country>                            </information>                        </match>                        <match id="1288349">                            <home id="15" name="club3"/>                            <away id="16" name="club4"/>                            <information>                                <country>england</country>                            </information>                        </match>                        <match id="1288350">                            <home id="17" name="club5"/>                            <away id="18" name="club6"/>                            <information>                                <country>italy</country>                            </information>                        </match>                        <match id="1288351">                            <home id="19" name="club7"/>                            <away id="20" name="club8"/>                            <information>                                <country>spain</country>                            </information>                        </match>                    </matchday> 

and output follow :

england 1288348 1288349 italy 1288350 spain 1288351 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -