I am having some trouble mixing PHP with XML.
I currently have a PHP file that takes variables from the URL string and I need to calculate something based on these variables, and then return the output in an XTML format.
I currently have my main config file that links to my xml generating file:
include('Xml.php');
$x = new xml();
$x->generate();
And my XML generating file is as follows:
<?php
Class XML {
public function generate() {
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('conv');
$root = $doc->appendChild($root);
$at = $doc->createElement('at');
$at = $root->appendChild($at);
$text = $doc->createTextNode("hi");
$text = $at->appendChild($text);
echo $doc->saveXML();
}
}
?>
But this doesn’t work – what am I doing wrong here – I know it’s probaby obvious but I am new to XML and can’t seem to get it working!
Should I be doing it differently? If so … how?
I’ve just tested your class with following code:
And I’ve got this result:
So your class works just fine and your error is somewhere else, eg. including wrong file.
Turn on
error_reportingand paste errors in comment.