0

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();
}
    ?>
1
  • and seems like u must use something like this: $d = $d->appendChild($books); Commented Nov 9, 2012 at 7:38

1 Answer 1

2
$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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.