Question Linq to XML query problem

satory

New member
Joined
Jul 28, 2010
Messages
1
Programming Experience
1-3
Hello,

I have the following xml document which would be taken from the web and stored into an XDocument object in vb.net,
HTML:
<blackoutrugby_api_response brt_timestamp="1280286311" brt_sql="2010-07-28 15:05:11" brt_iso_8601="2010-07-28T15:05:11+12:00" season="9" round="9" day="3">
  <reporters_summary fixtureid="5227049">
    <motm>3425548</motm>
    <home>
      <player id="7375386">
        <id>7375386</id>
        <position>1</position>
        <rating>6</rating>
        <potential>reached</potential>
        <performance>normal</performance>
      </player>
      <player id="3425539">
        <id>3425539</id>
        <position>2</position>
        <rating>3</rating>
        <potential>reached</potential>
        <performance>over</performance>
      </player>
      <player id="3425545">
        <id>3425545</id>
        <position>3</position>
        <rating>5</rating>
        <potential>reached</potential>
        <performance>under</performance>
      </player>
      <player id="3425526">
        <id>3425526</id>
        <position>4</position>
        <rating>4</rating>
        <potential>reached</potential>
        <performance>normal</performance>
      </player>
      <player id="3425552">
        <id>3425552</id>
        <position>5</position>
        <rating>3</rating>
        <potential>reached</potential>
        <performance>normal</performance>
      </player>
      <player id="7450351">
        <id>7450351</id>
        <position>6</position>
        <rating>4</rating>
        <potential>reached</potential>
        <performance>normal</performance>
      </player>
      <player id="3425527">
        <id>3425527</id>
        <position>7</position>
        <rating>4</rating>
        <potential>reached</potential>
        <performance>normal</performance>
      </player>
      <player id="9358542">
        <id>9358542</id>
        <position>8</position>
        <rating>3</rating>
        <potential>reached</potential>
        <performance>over</performance>
      </player>
    </home>
    <guest>
      <player id="3425562">
        <id>3425562</id>
        <position>1</position>
        <rating>6</rating>
        <potential>reached</potential>
        <performance>under</performance>
      </player>
      <player id="9251853">
        <id>9251853</id>
        <position>2</position>
        <rating>3</rating>
        <potential>reached</potential>
        <performance>under</performance>
      </player>
      <player id="5435379">
        <id>5435379</id>
        <position>3</position>
        <rating>5</rating>
        <potential>reached</potential>
        <performance>under</performance>
      </player>
      <player id="6743472">
        <id>6743472</id>
        <position>4</position>
        <rating>4</rating>
        <potential>reached</potential>
        <performance>normal</performance>
      </player>
    </guest>
  </reporters_summary>
</blackoutrugby_api_response>

As you can see the document gives information about players that played in a match, firstly on the home team and then secondly on the away team


What I'm looking to do is to be able to pull all the id's from the players that are on the home team so i get something along the lines of,
7375386, 3425539, 3425545, etc....


Thanks in advance
 
VB.NET:
Dim ids = xdoc...<home>.<player>.<id>
 
Looks like you have redundant information for player ID as it's in the id attribute and in the id element.

Here's an example of getting a list first using the attribute then using the id element.

VB.NET:
        Dim xdoc = XDocument.Load("C:\Temp\players.xml")

        Dim idsFromAttribute = (From node In xdoc...<home>.<player>
                                Select node.@id).ToList

        Dim idsFromElement = (From node In xdoc...<home>.<player>
                             Select node.<id>.Value).ToList
 
Back
Top