GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Thursday, March 10, 2011

PHP - Handling XML

To handle xml document using php, here's a bit of code of it:
For example, you have an xml document:
<?php

$xml = '<?xml version="1.0"?>';
$xml .= '<data>';
$xml .= '<name>Luna Maya</name>';
$xml .= '<city>Denpasar</city>';
$xml .= '<age>27</age>';
$xml .= '</data>';

$xmlDoc = new DOMDocument();
// if the xml document lies on the file, use $xmlDoc->load('your_file.xml');
$xmlDoc->loadXML($xml);

$name = $xmlDoc->getElementsByTagName('name');
echo $name->item(0)->nodeValue;

Share/Bookmark

No comments:

Post a Comment