/ Published in: PHP

This is a simple example of how to read and write XML that includes reading attributes and nodes.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $_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) { } ?>
Comments
