Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/12/2005, 21:13
plus_ultra
 
Fecha de Ingreso: diciembre-2005
Mensajes: 122
Antigüedad: 18 años, 4 meses
Puntos: 0
posible lo es (ya lo he echo) pero necesita un paso intermedio. lo que hago yo es, valiendome de las funciones de interprete xml, transformar al archivo en un array multidimensional. a partir de hay es muy facil trabajar. el script que utilizo es este:
Código:
Class XMLParser
{
	var $xml;
	var $depth;
	var $refer;
	var $index;
	var $root;
	
	function XMLParser($index = 'Index')
	{
		$this->xml = $this->refer = array();
		$this->index = $index;
		$this->depth = 0;
	}
	
	function tagStart($parser, $name, $attrs)
    {
	    if($this->depth)
	    {
		    if(isset($attrs[$this->index])) {
			    $this->refer[$this->depth] = &$this->refer[$this->depth - 1][$name][(int)$attrs[$this->index]];
		    }
		    else {
			    $this->refer[$this->depth] = &$this->refer[$this->depth - 1][$name];
		    }
	    }
	    else
	    {
		    $this->refer[] = &$this->xml[$name];
		    $this->root = $name;
	    }
	    
	    $this->depth++;
    }

    function tagEnd($parser, $name) {
	    $this->depth--;
    }

    function readData($parser, $data)
    {
	    if(strlen(trim($data))) {
		    $this->refer[$this->depth - 1] .= $data;
	    }	
	}
	
	function ParseXML($xml)
	{
	   $parser = xml_parser_create('ISO-8859-1');
	   
	   xml_set_object($parser, $this);
       xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
	   
       xml_set_element_handler($parser, 'tagStart', 'tagEnd');
       xml_set_character_data_handler($parser, 'readData');
       
       $file = explode("\n", $xml);
	   $lines = count($file);
       
       for($i = 0; $i < $lines; $i++)
       {
	       if(!xml_parse($parser, $file[$i])) {
    	       die("XML PARSE ERROR on line ".($i + 1)."\n");
	       }
       }
       
       xml_parser_free($parser);
	}
}
?>
los datos quedan guardados en en $xml. despues de eso es realmente sencillo trabajar.