browser lang:en
after have seen the way to transform a table from Mysql to XML, now we are goin to see the reverse way.
Here we need to traverse an XML and extract datas, using PHP 5 and DOMDocument we can use the function getElementsByTagName.
Example:
// DOMElement->getElementsByTagName() -- Gets elements by tagname
// nodeValue : The value of this node, depending on its type.
// Load XML File. You can use loadXML if you wish to load XML data from a string
/*
<hotels>
<hotel>
<hotelName>hilton</hotelName>
<cityName>rome</cityName>
</hotel>
<hotel>
<hotelName>melia</hotelName>
<cityName>london</cityName>
</hotel>
</hotels>
*/
$objDOM = new DOMDocument();
$objDOM->load("hotels.xml"); //make sure path is correct
$hotel = $objDOM->getElementsByTagName("hotel");
// for each note tag, parse the document and get values for
// tasks and details tag.
foreach( $hotel as $value )
{
//echo $hotel.' '.$value;
$hotelName = $value->getElementsByTagName("hotelName");
$nomeHotel = $hotelName->item(0)->nodeValue;
$cityName = $value->getElementsByTagName("cityName");
$nomeCitta = $cityName->item(0)->nodeValue;
echo "$nomeHotel :: $nomeCitta <br>";
}
PHP is one of the most widely used open-source server-side scripting languages that exist today. With over…
in:Scripts and tutorials (0 comments)In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS…
in:Scripts and tutorials (0 comments)Every single day, someone, somewhere is discussing something important to your business; your brand, your executives, your…
in:Scripts and tutorials (0 comments)The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a…
in:Scripts and tutorials (0 comments)Because of the near-spherical shape of the Earth, calculating an accurate distance between two points requires the use…
in:Scripts and tutorials (1 comments)With this script we can limit the download speed // local file that should be send to the client $local_file…
in:Scripts and tutorials (0 comments)Some hosts disabled the ini setting allow_url_fopen. This also means that the ability to easily grab images…
in:Scripts and tutorials (0 comments)The act to verify if a file exists, is one of more important tasks related to files operations,…
in:Scripts and tutorials (0 comments)
