Domanda

Given this XML code:

        private const XML:XML =
            <pref>
              <game id="0"/>
              <game id="9012">
                <user id="VK48058967" />
                <user id="MR14315189992643135976" />
                <user id="OK10218913103" />
              </game>
              <game id="9013">
                <user id="OK305894249541" />
                <user id="OK151358069597" />
                <user id="OK515549948434" />
              </game>
              <game id="9007">
                <user id="OK366541092321" />
                <user id="DE7062" />
                <user id="OK122700338897" />
              </game>
              <game id="8993">
                <user id="OK78476527766" />
                <user id="VK5692120" />
                <user id="OK61881379754" />
              </game>
              <game id="8997">
                <user id="OK96125953924" />
                <user id="OK21042473963" />
                <user id="OK278504320179" />
              </game>
              <game id="9001">
                <user id="OK189404154785" />
                <user id="OK143791302988" />
                <user id="OK526501872510" />
              </game>
              <game id="8996">
                <user id="VK6311467" />
                <user id="OK354027621556" />
                <user id="OK350266476029" />
              </game>
              <game id="8999">
                <user id="OK24459857299" />
                <user id="OK2104040126" />
                <user id="OK231866548025" />
              </game>
              <game id="8991">
                <user id="OK253525117889" />
                <user id="OK529081480134" />
              </game>
              <game id="8937">
                <user id="OK304672497140" />
                <user id="VK90145027" />
                <user id="OK338360548262" />
              </game>
              <game id="9005">
                <user id="OK40798070412" />
                <user id="DE7979" />
                <user id="OK531589632132" />
              </game>
              <game id="8942">
                <user id="VK20313675" />
                <user id="OK57368684455" />
                <user id="OK335173273155" />
              </game>
              <game id="8946">
                <user id="OK353118989212" />
                <user id="OK351923295875" />
              </game>
              <game id="9000">
                <user id="DE7470" />
                <user id="OK209621043939" />
              </game>
              <game id="9011">
                <user id="OK321594287223" />
                <user id="DE7692" />
                <user id="OK260177162376" />
              </game>
              <game id="9010">
                <user id="OK31902424355" />
                <user id="OK357833936215" />
              </game>
            </pref>;        

I can count the total number of game elements in the XML.game with:

            trace('All games: ' + XML.game.length());

Is there please some way to print the number of all game elements having the exact number of 3 user children? And also count all such elements with less than 3 user children?

            trace('Vacant games: ' + XML.game.XXXXX);
            trace('Full games: ' + XML.game.XXXX);

The backgound is, that I have a Flex game, where up to 3 players can sit at a playing table and I'm trying to display the number of All, Vacant and Full playing tables there (the top left row with RadioButtons, sorry for the non-English language):

enter image description here

I'm reading the XMLList doc, but don't see how to do it with one-liners, I only can see how to do it with loops...

È stato utile?

Soluzione

Try to use the following:

xml.game.(children().length() == 3).length();
xml.game.(children().length() < 3).length();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top