使用LINQ to XML Query从特定XML元素获取后代

时间:2016-04-06 10:41:18

标签: asp.net xml vb.net linq linq-to-xml

这是我的XML

<xml time="1459844720">
<Competitions>
<Competition name="1. Bundesliga" id="GER_1" season="2015/2016" country="Germany" country_id="GER"/>
<Competition name="Allsvenskan" id="SWE_1" season="2016" country="Sweden" country_id="SWE"/>
<Competition name="Belgian Pro League" id="BEL_1" season="2015/2016" country="Belgium" country_id="BEL"/>
<Competition name="Championship" id="ENG_2" season="2015/2016" country="England" country_id="ENG">
<Matches>...</Matches>
</Competition>
<Competition name="Copa del Rey" id="ESP_C_1" season="2015/2016" country="Spain" country_id="ESP"/>
<Competition name="Coppa Italia" id="ITA_C_1" season="2015/2016" country="Italy" country_id="ITA"/>
<Competition name="Coupe de France" id="FRA_C_1" season="2015/2016" country="France" country_id="FRA"/>
<Competition name="DFB Pokal" id="GER_C_1" season="2015/2016" country="Germany" country_id="GER"/>
<Competition name="Eredivisie" id="NED_1" season="2015/2016" country="Netherlands" country_id="NED"/>
<Competition name="European Championship" id="INT_5" season="2016" country="International" country_id="INT"/>
<Competition name="FA Cup" id="ENG_C_1" season="2015/2016" country="England" country_id="ENG"/>
<Competition name="League of Ireland" id="IRL_1" season="2016" country="Ireland" country_id="IRL"/>
<Competition name="Liga MX" id="MEX_1" season="2016" country="Mexico" country_id="MEX"/>
<Competition name="Ligue 1" id="FRA_1" season="2015/2016" country="France" country_id="FRA"/>
<Competition name="Major League Soccer" id="USA_1" season="2016" country="USA" country_id="USA"/>
<Competition name="Premier League" id="ENG_1" season="2015/2016" country="England" country_id="ENG"/>
<Competition name="Premiership" id="SCO_1" season="2015/2016" country="Scotland" country_id="SCO">...</Competition>
<Competition name="Primeira Liga" id="POR_1" season="2015/2016" country="Portugal" country_id="POR"/>
<Competition name="Primera Division" id="ESP_1" season="2015/2016" country="Spain" country_id="ESP"/>
<Competition name="Russia Premier League" id="RUS_1" season="2015/2016" country="Russia" country_id="RUS"/>
<Competition name="Serie A" id="ITA_1" season="2015/2016" country="Italy" country_id="ITA"/>
<Competition name="Süper Lig" id="TUR_1" season="2015/2016" country="Turkey" country_id="TUR"/>
<Competition name="Superligaen" id="DEN_1" season="2015/2016" country="Denmark" country_id="DEN"/>
<Competition name="Tippeligaen" id="NOR_1" season="2016" country="Norway" country_id="NOR"/>
<Competition name="UEFA Champions League" id="INT_3" season="2015/2016" country="International" country_id="INT">
<Matches>
<Match match_id="195b0cfda1cc7e16c762699080a2954a" match_name="Bayern Munich-Benfica" match_date="2016-04-05 20:45:00" match_status="notstarted" home_id="BAYERN-MUNICH" home_name="Bayern Munich" away_id="BENFICA" away_name="Benfica"/>
<Match match_id="e513150fea7879711ddefd18c7cd78a9" match_name="Barcelona-Atletico Madrid" match_date="2016-04-05 20:45:00" match_status="notstarted" home_id="BARCELONA" home_name="Barcelona" away_id="ATLETICO-MADRID" away_name="Atletico Madrid"/>
</Matches>
</Competition>
<Competition name="UEFA Europa League" id="INT_23" season="2015/2016" country="International" country_id="INT"/>
</Competitions>
</xml>

我想获得所有比赛名称和比赛名称。结果将是这样的:

  • 锦标赛
    读诺丁汉森林 伯明翰,布莱顿
    布伦特福德,博尔顿
    利兹 - 女王公园巡游者
    布里斯托尔市 - 罗瑟勒姆
    伊普斯维奇,查尔顿
    米德尔斯堡,哈德斯菲尔德
    米尔顿凯恩斯Dons-Wolverhampton流浪者
    普雷斯顿 - 富勒姆

  • 足总杯

  • 英超联赛

这是我的代码

Sub GetData()
        Dim doc = XDocument.Load("E:\Web Project\Bootstrap\Score\Score\fixtures.xml")
        Dim compCountry As String = "England"
        Dim compQuery = From competition In doc.Descendants.Elements("Competition")
                   Select New With {
                        .Name = competition.Attribute("name").Value,
                        .Country = competition.Attribute("country").Value,
                        .Child = competition.Descendants("Match").Value
                    }


        Dim comp = compQuery.First
        Dim comps = compQuery.ToList

        Dim sTable


        Dim i As Integer
        Dim j As Integer
        For i = 0 To comps.Count - 1

            sTable = comps(i).Name & " - " & comps(i).Country
            lblTest.Text = lblTest.Text & sTable & "<br>"
            Dim mQuery = From x In doc.Descendants("Match")
                         Select New With {
                             .Match = x.Attribute("match_name").Value
                         }

            Dim mRes = mQuery.ToList
            For j = 0 To mRes.Count - 1
                Dim sMatch As String = "&nbsp;&nbsp;&nbsp;" & mRes(j).Match
                lblTest.Text = lblTest.Text & sMatch & "<br>"
            Next
        Next
    End Sub

但这是我从上面的代码中得到的

1. Bundesliga - Germany
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Allsvenskan - Sweden
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Belgian Pro League - Belgium
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Championship - England
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Copa del Rey - Spain
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Coppa Italia - Italy
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Coupe de France - France
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
DFB Pokal - Germany
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Eredivisie - Netherlands
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
European Championship - International
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
FA Cup - England
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
League of Ireland - Ireland
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Liga MX - Mexico
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Ligue 1 - France
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Major League Soccer - USA
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Premier League - England
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Premiership - Scotland
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Primeira Liga - Portugal
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Primera Division - Spain
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Russia Premier League - Russia
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Serie A - Italy
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Süper Lig - Turkey
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Superligaen - Denmark
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
Tippeligaen - Norway
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
UEFA Champions League - International
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid
UEFA Europa League - International
   Reading-Nottingham Forest
   Birmingham-Brighton
   Brentford-Bolton
   Leeds-Queens Park Rangers
   Bristol City-Rotherham
   Ipswich-Charlton
   Middlesbrough-Huddersfield
   Milton Keynes Dons-Wolverhampton Wanderers
   Preston-Fulham
   Sheffield Wednesday-Blackburn
   Derby-Hull
   Burnley-Cardiff
   Partick T.-Dundee U.
   Dundee FC-Celtic
   Bayern Munich-Benfica
   Barcelona-Atletico Madrid

任何人都可以帮忙找到解决方案吗?

1 个答案:

答案 0 :(得分:0)

首先,您没有提供完整的XML文件。以下样品是根据您在说明中提到的内容制备的。您可以通过以下方式尝试:

Public Sub test00()
        Dim frag As XElement = <xml time="1459844720">
                                   <Competitions>
                                       <Competition name="1. Bundesliga" id="GER_1" season="2015/2016" country="Germany" country_id="GER"/>
                                       <Competition name="Allsvenskan" id="SWE_1" season="2016" country="Sweden" country_id="SWE"/>
                                       <Competition name="Belgian Pro League" id="BEL_1" season="2015/2016" country="Belgium" country_id="BEL"/>
                                       <Competition name="Championship" id="ENG_2" season="2015/2016" country="England" country_id="ENG">
                                           <Matches>...</Matches>
                                       </Competition>
                                       <Competition name="Copa del Rey" id="ESP_C_1" season="2015/2016" country="Spain" country_id="ESP"/>
                                       <Competition name="Coppa Italia" id="ITA_C_1" season="2015/2016" country="Italy" country_id="ITA"/>
                                       <Competition name="Coupe de France" id="FRA_C_1" season="2015/2016" country="France" country_id="FRA"/>
                                       <Competition name="DFB Pokal" id="GER_C_1" season="2015/2016" country="Germany" country_id="GER"/>
                                       <Competition name="Eredivisie" id="NED_1" season="2015/2016" country="Netherlands" country_id="NED"/>
                                       <Competition name="European Championship" id="INT_5" season="2016" country="International" country_id="INT"/>
                                       <Competition name="FA Cup" id="ENG_C_1" season="2015/2016" country="England" country_id="ENG"/>
                                       <Competition name="League of Ireland" id="IRL_1" season="2016" country="Ireland" country_id="IRL"/>
                                       <Competition name="Liga MX" id="MEX_1" season="2016" country="Mexico" country_id="MEX"/>
                                       <Competition name="Ligue 1" id="FRA_1" season="2015/2016" country="France" country_id="FRA"/>
                                       <Competition name="Major League Soccer" id="USA_1" season="2016" country="USA" country_id="USA"/>
                                       <Competition name="Premier League" id="ENG_1" season="2015/2016" country="England" country_id="ENG"/>
                                       <Competition name="Premiership" id="SCO_1" season="2015/2016" country="Scotland" country_id="SCO">...</Competition>
                                       <Competition name="Primeira Liga" id="POR_1" season="2015/2016" country="Portugal" country_id="POR"/>
                                       <Competition name="Primera Division" id="ESP_1" season="2015/2016" country="Spain" country_id="ESP"/>
                                       <Competition name="Russia Premier League" id="RUS_1" season="2015/2016" country="Russia" country_id="RUS"/>
                                       <Competition name="Serie A" id="ITA_1" season="2015/2016" country="Italy" country_id="ITA"/>
                                       <Competition name="Süper Lig" id="TUR_1" season="2015/2016" country="Turkey" country_id="TUR"/>
                                       <Competition name="Superligaen" id="DEN_1" season="2015/2016" country="Denmark" country_id="DEN"/>
                                       <Competition name="Tippeligaen" id="NOR_1" season="2016" country="Norway" country_id="NOR"/>
                                       <Competition name="UEFA Champions League" id="INT_3" season="2015/2016" country="International" country_id="INT">
                                           <Matches>
                                               <Match match_id="195b0cfda1cc7e16c762699080a2954a" match_name="Bayern Munich-Benfica" match_date="2016-04-05 20:45:00" match_status="notstarted" home_id="BAYERN-MUNICH" home_name="Bayern Munich" away_id="BENFICA" away_name="Benfica"/>
                                               <Match match_id="e513150fea7879711ddefd18c7cd78a9" match_name="Barcelona-Atletico Madrid" match_date="2016-04-05 20:45:00" match_status="notstarted" home_id="BARCELONA" home_name="Barcelona" away_id="ATLETICO-MADRID" away_name="Atletico Madrid"/>
                                           </Matches>
                                       </Competition>
                                       <Competition name="UEFA Europa League" id="INT_23" season="2015/2016" country="International" country_id="INT"/>
                                   </Competitions>
                               </xml>
        Dim q1 = frag...<Competition>.Select(Function(c) c.@name).Distinct
        Dim sb As New StringBuilder
        For Each cn$ In q1
            sb.AppendLine("• " & cn)
            Dim q2 = frag...<Match>.Where(Function(c) c.Parent.Parent.@name = cn)
            If q2.Count > 0 Then
                For Each ele0 As XElement In q2
                    sb.AppendLine(String.Format("{0} — {1}", ele0.Parent.Parent.@country, ele0.@match_name))
                Next ele0
            End If
        Next cn
        MsgBox(sb.ToString)
    End Sub

希望这会有所帮助......