Mysql
 sql >> Database >  >> RDS >> Mysql

Formato XML non valido - Come evitarlo

Potresti usare un XMLWriter per garantire una codifica corretta e simili.

<?php
$stmt = new Dummy;
$stmt->bind_result($foo);

$xml = new XMLWriter(); 
$xml->openURI('php://output'); 
$xml->setIndent(true);
$xml->startDocument(); 

$xml->startElement("xml"); 
while ( $stmt->fetch() ) {
    $xml->startElement("RECORD");
    $xml->writeElement('FOO', $foo);
    $xml->endElement(); // RECORD
}
$xml->endElement(); // xml


class Dummy {
    public function bind_result(&$var) {
        $this->var = &$var;
    }

    public function fetch() {
        static $arr = array('Barnes & Noble', 'Barnum & Bailey', "Buy'n'Large");
        if ( current($arr) ) {
            $this->var = current($arr);
            next($arr);
            return true;
        }
        return false;
    }
}