Reputation: 263
I thought that I was properly creating an xml document in my php script from a mysql query, but I am not getting an xml document in return (with no php errors to help me) even though the mysql query works!
<?php
...
$result = $mysqli->query($sql);
if ($result) { //this query works, but no xml document produced as a result
$d = new DOMDocument();
$books = $d->createElement('hey');
$hey->setAttribute('check','The Adventures of Tom Sawyer');
$d->appendChild($books);
$d->appendChild($hey);
$d->appendChild($books);
echo $d->saveXML();
}
?>
Upvotes: 0
Views: 50
Reputation: 96159
$d->setAttribute('check','The Adventures of Tom Sawyer');
$d "is" the DOMDocument object and there is no DOMDocument::setAttribute() method.
Either use DOMElement::setAttribute() or DOMDocument::createAttribute()
if ($result) {
$d = new DOMDocument();
$books = $d->createElement('hey');
$books->setAttribute('check','The Adventures of Tom Sawyer');
$d->appendChild($books);
echo $d->saveXML();
}
Upvotes: 2