comparison php/requestKey.php @ 2630:3986de98f04a

Use DOMDocument
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 19 Jan 2017 12:08:26 +0000
parents 6324f500beb3
children a5ec4089d990
comparison
equal deleted inserted replaced
2629:6324f500beb3 2630:3986de98f04a
53 die("<response><state>ERROR</state><key>".$key."</key><message>Could not open file for writing</message></response>"); 53 die("<response><state>ERROR</state><key>".$key."</key><message>Could not open file for writing</message></response>");
54 } 54 }
55 fclose($fileHandle); 55 fclose($fileHandle);
56 // TODO: 56 // TODO:
57 // Generate the XML Base file and save it 57 // Generate the XML Base file and save it
58 $doc_struct = new SimpleXMLElement('<waetresult/>'); 58 $doc_struct = new DOMDocument;
59 $doc_struct->addAttribute("key",$key); 59 $doc_struct->preserveWhiteSpace = false;
60 $doc_struct->formatOutput = true;
61 $doc_struct->loadXML("<waetresult/>");
60 // Add the root 62 // Add the root
61 if (file_exists($testURL)) { 63 if (file_exists($testURL)) {
62 $test_proto = simplexml_load_string(file_get_contents($testURL, FILE_TEXT)); 64 $test_proto = new DOMDocument;
63 $doc_struct->addChild($test_proto); 65 $test_proto->loadXML(file_get_contents($testURL, FILE_TEXT));
66 $test_proto = $doc_struct->importNode($test_proto, true);
67 $doc_struct->documentElement->appendChild($test_proto);
64 } 68 }
65 // Add start time 69 // Add start time
66 // Add IP Address information 70 // Add IP Address information
67 // Save the file 71 // Save the file
68 $doc_struct->asXML($filename); 72 $newdoc->saveXML($filename);
69 echo "<response><state>OK</state><key>".$key."</key></response>"; 73 echo "<response><state>OK</state><key>".$key."</key></response>";
70 ?> 74 ?>