Codice della classe:
Codice PHP:
import giocatore;
class navigazioneXML {
private static var filexml:String;
private static var myarray:Array;
private static var rosa:Array;
private static var mioxml:XML;
public static function ApriXML(nazione:String):Array {
filexml = "C:/Users/William Lawson/Documents/Università/ppm/Progetto PPM/Contents/xml/"+nazione+".xml";
rosa = new Array();
myarray = new Array();
mioxml = new XML();
mioxml.load(filexml);
mioxml.onLoad = function(success) {
if (mioxml.loaded) {
myarray = mioxml.childNodes;
rosa = Dati();
}
};
return rosa;
}
private static function Dati():Array {
var k:Number;
for (k=0; k<=myarray.length; k++) {
if (myarray[k].nodeName == "giocatore") {
rosa.push(new giocatore(myarray[k].attributes.nome, myarray[k].childNodes[0].childNodes, myarray[k].childNodes[1].childNodes, myarray[k].childNodes[2].childNodes, myarray[k].childNodes[3].childNodes, "nessuna foto"));
}
}
return rosa;
}
}
Questa invece è la struttura del file xml:
Codice PHP:
<?xml version="1.0" encoding="UTF-8"?>
<giocatore nome='Enrico Patrizio'><Ruolo>Estremo</Ruolo><Club>Carrera Petrarca Padova</Club><Presenze>3</Presenze><Punti>0</Punti></giocatore>
<giocatore nome='Ezio Galon'><Ruolo>Ala</Ruolo><Club>Overmach Cariparma</Club><Presenze>19</Presenze><Punti>5</Punti></giocatore>
<giocatore nome='Kaine Robertson'><Ruolo>Ala</Ruolo><Club>Arix Viadana</Club><Presenze>30</Presenze><Punti>60</Punti></giocatore>
<giocatore nome='Alberto Sgarbi'><Ruolo>Ala</Ruolo><Club>Benetton Treviso</Club><Presenze>2</Presenze><Punti>0</Punti></giocatore>
<giocatore nome='Mirco Bergamasco'><Ruolo>Centro</Ruolo><Club>Stade Français</Club><Presenze>52</Presenze><Punti>75</Punti></giocatore>
<giocatore nome='Gonzalo Canale'><Ruolo>Centro</Ruolo><Club>Clermont- Auvergne</Club><Presenze>41</Presenze><Punti>30</Punti></giocatore>
<giocatore nome='Andrea Masi'><Ruolo>Centro</Ruolo><Club>Biarritz Olympique</Club><Presenze>40</Presenze><Punti>50</Punti></giocatore>
<giocatore nome='Alessio Galante'><Ruolo>Centro</Ruolo><Club>Rolly Gran Parma</Club><Presenze>2</Presenze><Punti>0</Punti></giocatore>