Revision: 7435
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 24, 2008 05:16 by donkeykong
Initial Code
<?php session_start(); $_SESSION['arrConfig']; $docConfigXML = new DOMDocument; $docConfigXML->preserveWhiteSpace = FALSE; $docConfigXML->load( 'resources/xml/config.xml' ); $_SESSION['arrConfig']['fax'] = trim($docConfigXML->getElementsByTagName("fax")->item(0)->getAttribute('value')); $_SESSION['arrConfig']['phone'] = trim($docConfigXML->getElementsByTagName("phone")->item(0)->nodeValue); echo $_SESSION['arrConfig']['fax']; echo "<br />"; echo $_SESSION['arrConfig']['phone']; $strConfigXML = ""; $fax = "702-555-1faxxx"; $phone = '702-555-phone'; $strConfigXML = <<<END <?xml version="1.0" encoding="utf-8"?> <config> <fax value='$fax' /> <phone> $phone </phone> </config> END; $file = "resources/xml/config.xml"; writeFile($file,$strConfigXML); function writeFile($file,$strFileContent) { $fh = fopen($file, 'w' ) or die ("can't create file"); fwrite($fh, $strFileContent); fclose($fh); } ?>
Initial URL
Initial Description
This is a simple example of how to read and write XML that includes reading attributes and nodes.
Initial Title
write and read XML
Initial Tags
xml
Initial Language
PHP