Ciao a tutti,
cerco armai da ore sul web una risposta al mio semplice problema che vi vado ad illustrare.
PHP Version 5.1.4
Sto creando l'aggiornameto di un contenuto per l'home page di un sito, e dato che il contenuto è limitato, (massimo due news), volevo per la prima volta provare a utilizzare xml e dom.
Questo il mio xml:
Dopo svariate ricerche ho trovato come leggere con dom l'xml:codice:<?xml version="1.0" encoding="iso-8859-1"?> <news> <new> <title>titolo1</title> <date>25/09/2007</date> <body>Some text</body> </new> <new> <title>titolo2</title> <date>23/09/2007</date> <body>Some text</body> </new> </news>
Non riesco però a scrivere sul file.codice:<?php $xml = new DomDocument('1.0'); $xml->load('library.xml'); ?> <html> <head> <title>News azalee</title> </head> <body> <? php foreach($xml->getElementsBytagName('new') as $new): $title = $new->getElementsByTagName('title')->item(0)->firstChild->nodeValue; $date = $new->getElementsByTagName('date')->item(0)->firstChild->nodeValue; $body = $new->getElementsByTagName('body')->item(0)->firstChild->nodeValue; ?> <h1><?php echo($title) ?></h1> <h2><?php echo($date) ?></h2> <?php echo($body) ?></p> <?php endforeach; ?> </html>
Il mio unico scopo per adesso è sostituire ad esempio il body di una new.
Come posso fare?


 
			
			 
					
					
					
						 Rispondi quotando
  Rispondi quotando