Advertisement
william73

Xml

Dec 15th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. $stmt = $conn->query('SELECT user_name, user_email, user_pass FROM users');
  2. $stmt->setFetchMode(PDO::FETCH_ASSOC);
  3.  
  4. $document = new DOMDocument('1.0', 'UTF-8');
  5.  
  6.  
  7. $annunci = $document->createElement('annunci');  // 1. Nodo Annunci
  8.  
  9. foreach ($stmt as $row) {
  10.     $annuncio = $document->createElement('annuncio');  // 2. Ciclo Nodo Annuncio
  11.    
  12.    
  13.   //  $entry->setAttribute('submissionDate', $row['date_entered']);
  14.  
  15.     $annuncio->appendChild($document->createElement('id_annuncio_immobile', $row['user_name']));
  16.     $annuncio->appendChild($document->createElement('idtipologiaimmobile', $row['user_email']));
  17.  
  18.     // and so on
  19.  
  20.     // CDATA sections are slightly different
  21.       $description = $document->createElement('descrizione');
  22.       $description->appendChild($document->createCDATASection($row['user_pass']));
  23.       $annuncio->appendChild($description);
  24.      
  25.      
  26.    
  27.             // Inizio Sub Ciclo
  28.            
  29.            
  30.            
  31.             $stmt2 = $conn->query('SELECT nome_file FROM foto_news');
  32.             $stmt2->setFetchMode(PDO::FETCH_ASSOC);
  33.            
  34.            
  35.            
  36.            
  37.             //
  38.         //  $immagini = $document->createElement('immagini');  // 2. Ciclo Nodo Annuncio   
  39.         //  $annuncio->appendChild($immagini);
  40.            
  41.             $b = $document->createElement( "immagini" );
  42.            
  43.            
  44.             foreach ($stmt2 as $row) {
  45.            
  46.                   /*
  47.                   $annuncio1 = $document->createElement('annuncio1');  // 2. Ciclo Nodo Annuncio
  48.                    $annuncio1->appendChild($document->createElement('id_annuncio_immobile', $row['nome_file']));
  49.                   $annunci->appendChild($annuncio1); // 2. Ciclo Nodo Annuncio
  50.                 */
  51.                
  52.                
  53.                     $immagine = $document->createElement('immagine');
  54.                  
  55.                     $immagine->appendChild($document->createElement('link', $row['nome_file']));
  56.                  
  57.                     $annuncio->appendChild($immagine);
  58.                
  59.             // $annuncio->appendChild($immagini);  
  60.             }
  61.            
  62.    
  63.             $annuncio->appendChild($b);
  64.    
  65.            
  66.             // Fine Sub Ciclo
  67.        
  68.  
  69.     $annunci->appendChild($annuncio); // 2. Ciclo Nodo Annuncio
  70. }
  71.  
  72. $document->appendChild($annunci);    // 1. Nodo Annunci
  73.  
  74. // Set the appropriate content-type header and output the XML
  75. header('Content-type: application/xml');
  76. echo $document->saveXML();
  77. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement