METAL IMPACT
P
U
B
Cliquez SVP P
U
B
L ultime Webzine orienté Metal qui se renouvelle au quotidien

MI Facebook | MI YouTube | CD Reviews | DVD Reviews | Book Reviews | Interviews | Live Reports | Concours | Forums | Radio | Photos | M-I Tshirt | Contact | M-I Banner
Fermer/Ouvrir ce bloc Rechercher sur M-I


Avancee | Aidez-moi
Fermer/Ouvrir ce bloc M-I Membres
· Page d'accueil
· S'enregistrer
· Liste des Membres
· M-I Flux RSS
· M-I sur Facebook
· M-I sur YouTube
· M-I sur Twitter
· M-I sur Google+
· Top 15 des Rubriques
· M-I FAQ
· M-I Tshirt
· M-I Skin Firefox
Fermer/Ouvrir ce bloc Book Reviews Aléatoires
Voir les autres
Fermer/Ouvrir ce bloc Interviews Aléatoires
· THE DILLINGER E…
· CRYPTOPSY (ca) …
· DEADLY CARNAGE …
· LOTSAGABE (FRA)…
· DARK POETRY (FR…
Voir les autres
Fermer/Ouvrir ce bloc CD Reviews Aléatoires
Voir les autres
Fermer/Ouvrir ce bloc Rejoins-nous sur Facebook
Fermer/Ouvrir ce bloc Live Reports Aléatoires
· TOTO (usa) - Dô…
· MADINA LAKE (us…
· SHAKA PONK (FRA…
· SCORPIONS (de) …
· SYLAK OPEN AIR …
Voir les autres
Fermer/Ouvrir ce bloc DVD Reviews Aléatoires
Voir les autres
Fermer/Ouvrir ce bloc Qui est en Ligne ?
Il y a actuellement 109 invités et 0 membres en ligne

Vous êtes un visiteur anonyme. Inscrivez-vous gratuitement en cliquant ici.

Fermer/Ouvrir ce bloc M-I Jeux

Deviens un pro de la batterie en cliquant ici ou (Entraîne toi sur la batterie de Danny Carey de TOOL)

P
U
B
Cliquez SVP P
U
B

# # XML_node.objet # # This object is an XML node representation # # /- name (string) # xml_node --- attributes (array) # \- children (array) or value (string) class xml_node { var $name; var $attributes = array(); var $children = array(); var $value = ""; function xml_node($name,$attributes,$children=array(),$value="") { $this->name = $name; if (is_array($attributes)) { $this->attributes = $attributes; } $this->children = $children; $this->value = $value; } } # # xml_tree class # # This object parses an XML stream and offers a tree composed by xml_nodes # class xml_tree { var $xml_stream; var $current_node; var $root_node; var $index; var $value; function xml_tree() { $this->root_node = new xml_node("__ROOT_NODE",array()); $this->current_node = $this->root_node; } function add_tree($xml_stream) { # Managing the parser $this->xml_stream = $xml_stream; $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0); xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1); if (!xml_parse_into_struct($xml_parser,$this->xml_stream,$this->value,$this->index)) { xml_parser_free($xml_parser); die("XML Parse error"); } xml_parser_free($xml_parser); # Now, $this->value and $this->index are informed, we can use the get_node methode. $tab_result = $this->get_node(0,count($this->value) - 1); $this->root_node->children[] = $tab_result[0]; $this->current_node = $this->root_node; } function get_node($index_start,$index_stop) { #echo "


\n"; #echo "GET-NODE($index_start,$index_stop)
\n"; # What we are going to return is an array of xml_nodes $return_tab = array(); # depth is only here to check if everything is all right $tab_node = $this->value[$index_start]; $depth = $tab_node["level"]-1; # Now we have to be sure we do not forget a single node for ($index = $index_start;$index <= $index_stop;$index++) { #echo "\$index = $index
"; # get the current node $tab_node = $this->value[$index]; # what type of node is it ? switch($tab_node["type"]) { case "complete" : # Depth integrity check if ($tab_node["level"] != $depth+1) { die("ERREUR # contrainte d'intégrité au noeud complet $index, niveau $depth + 1 au lieu de ".$tab_node["level"]); } #echo "Noeud complet trouvé position $index TAG ".$tab_node["tag"]."
\n"; # Easy one, no children to manage, only a value... $return_tab[] = new xml_node($tab_node["tag"],$tab_node["attributes"],"",$tab_node["value"]); break; case "open" : # Depth integrity check if ($tab_node["level"] != $depth +1 ) { die("ERREUR # contrainte d'intégrité au noeud ouvert $index, niveau $depth au lieu de ".$tab_node["level"]); } # Open tag, we re-use this methode to return its children # Where is the correspondong close tag ? $node_index = $this->index[$tab_node["tag"]]; $flipped_node_index = array_flip($node_index); #echo "This ".$tab_node["tag"]." is at coords ".$flipped_node_index[$index]."
"; $i=1; do { $next_index = $node_index[$flipped_node_index[$index] + $i++]; $next_tag=$this->value[$next_index]; } while ($next_tag["level"]!=$tab_node["level"]); #echo "Ouverture de noeud détectée pos $index TAG ".$tab_node["tag"]."
\n   Parcours jusqu au $next_index
\n"; # good, we can now instanciate our node $return_tab[] = new xml_node($tab_node["tag"],$tab_node["attributes"],$this->get_node($index+1,$next_index),""); # As we called the get_node methode, we are sure that nodes have been parsed to the corresponding close tag $index = $next_index; break; case "close" : # Depth integrity check if ($tab_node["level"] != $depth ){ die("ERREUR # contrainte d'intégrité au noeud fermé $index, niveau $depth au lieu de ".$tab_node["level"]); } #echo "Fermeture de noeud detectée pos $index TAG ".$tab_node["tag"]."

\n"; # This ugly thing is useless because reaching a close tag means that $index==$index_stop but who knows ? =) # it will be skipped soon $index = $index_stop; break; default: die("Erreur de type de TAG non déterminé :'".$tab_node["type"]."'"); } } # We are out ... returns the array with collected children... return ($return_tab); } # this function browse the xml tree and set the current node to the selected node function give_node($path) { if ($path[0]=="/") { $current_node=$this->root_node; $path=substr($path,1); #echo "ABSOLUTE PATH GIVEN=$path
"; } else { $current_node = $this->current_node; } #echo "PATH GIVEN=$path
"; $tab_path = split("/",$path); foreach ($tab_path as $node_expr) { #echo "STUDYING EXPR='$node_expr'
"; $node = $current_node; $expr_tab = split("\?",$node_expr); $node_name = $expr_tab[0]; $attr_tab = 0; if (count($expr_tab)>1) { ##echo "TROUVE AU MOINS UNE CONDITION SUR LES ATTRIBUTS...
"; $attr_expr_tab=split(",",$expr_tab[1]); $attr_tab=array(); foreach($attr_expr_tab as $attr_expr) { $attr_split_expr=split("=",$attr_expr); $attr_tab[$attr_split_expr[0]]=$attr_split_expr[1]; } } $last=0; foreach ($node->children as $children) { #echo "COMPARING WITH '$children->name'
"; if ($children->name == $node_name) { ##echo "TROUVE NOEUD CORRESPONDANT $node_name
"; if (is_array($attr_tab)) { $node_attributes = $children->attributes; foreach ($attr_tab as $key=>$value) { if ($node_attributes[$key] == $value) { #echo "ATTRIBUTE & CHANGE CURRENT NODE TO ".$children->name."
"; $current_node = $children; $last = 1; } } } else { ##echo "CHILD=".$children->name."
"; #echo "CHANGE CURRENT NODE TO ".$children->name."
"; $current_node = $children; $last=1; } } if ($last) { break; } } if (!$last) { #echo "PATH ERROR $node_name
"; #die("MMmmmh It seems that this file is not a DIA XML format...sorry..."); return 0; } } return $current_node; } function browse_tree($path) { $node = $this->give_node($path); if (is_object($node)) { $this->current_node = $node; return 1; } return 0; } # this method dumps an html representation of the xml tree function xml_show($node = "",$level=0,$last=0) { if ($node=="") { $node=$this->root_node; } if (!is_object($node)) { die("ERROR : node is not an object"); } $line=""; for($i=1;$i<=$level;$i++) { if ((i==$level-1) and ($last)) { $line.="      "; } else { $line.="     |"; } if ($i==$level) { $line.="`-"; } } $line.=$node->name; #echo $line; $line.="".count($node->children).""; if (count($node->children)==1) { $line.=" (".$node->value.")
\n"; echo "$line"; } else { $line.="
\n"; echo "$line"; $i=1; foreach($node->children as $children) { if ($i==count($node->children)) { $this->xml_show($children,$level+1,1); } else { $this->xml_show($children,$level+1); } $i++; } } } #END_CLASS }