Ver Mensaje Individual
  #11 (permalink)  
Antiguo 06/03/2011, 13:54
fefefefe
 
Fecha de Ingreso: junio-2010
Mensajes: 128
Antigüedad: 13 años, 10 meses
Puntos: 2
Respuesta: Problemas con addAtributte

revisando por el foro pude hacer algo asi con DOM, efectivamente puedo hacer que el registro lo coloque primero pero quiero agregarle un hijo


Código PHP:


 
try {  
           
$dom = new DOMDocument();          
  
           
$dom->load('xml/custom.xml');

           
$node $dom->createElement('video');        
  
           
$node->setAttribute('title''documental2');  
  
           
$node->setAttribute('link''documental2');    
  
           
$node->setAttribute('thumb''documental2');    
           
          
  
      

            
$xpath  = new DOMXPath($dom);        
  
          
$first  $xpath->query('//video[1]')->item(0);

            if(
null === $first) {
  
                
$dom->documentElement->appendChild($node);            
  
            } else {
  
                
$first->parentNode->insertBefore($node$first);
            }
            
$dom->save('xml/custom.xml');

    } catch(
Exception $e) {
  
            
//handle exception
  
      


por que solo em lo guarda asi


<video id="gede" titulo="gede" fecha="gede" contenido="gede"/>



y quiero quede asi




<video title="Iguazú" link="http://www.youtube.com/lgPeQGT0NZQ" thumb="thumbs/animation/ratatouille.jpg">
<short>Cataratas del Iguazú</short>
</video>