XML File using PHP - Altering the First Two Lines UTF-8 -
i have xml file formatted in specific way specific nodes. have following php code (in test.php) create new xml file each week or else append xml file if entry within same week;
$filename = date('y-w').'.xml'; //2014-26.xml //check if file exists if (file_exists($filename)) { // call xml appendfile function appendfile($filename); } else { // call xml createfile function createfile($filename); }
when new file created (e.g. 2014-26.xml), top 2 lines of xml file follows;
<?xml version="1.0"?> <entry>
i need top 2 lines be;
<?xml version=”1.0” encoding=”utf-8”?> <document xmlns=”urn:iso:std:iso:20022:tech:xsd:pain.008.001.02” xmlns:xsi=”http://www.w3.org/2001/xmlschema-instance”>
in test.php file, have following function causing "entry" node displayed;
function addroot(&$xml) { $xml->appendchild($xml->createelement("entry")); }
i call function within createfile function follows;
// create root element, , add dom addroot($xml);
i tried changing "entry" second line require received error. have ideas how change these top 2 lines suit requirements have been attempting days no avail? new xml. thanks.
solution part 1;
i fixed first line entering adding "utf-8" line of code follows;
// create new dom document $xml = new domdocument('1.0', 'utf-8');
solution part 2;
on off chance else may have problem, able put second line in altering code to;
function addroot(&$xml) { $root = $xml->createelementns('urn:iso:std:iso:20022:tech:xsd:pain.008.001.02', 'document'); $xml->appendchild($root); $root->setattributens('http://www.w3.org/2000/xmlns/' ,'xmlns:xsi', 'http://www.w3.org/2001/xmlschema-instance'); }
Comments
Post a Comment