Horde_Xml_Wbxml_Decoder::decodeToString PHP Method

decodeToString() public method

However the preferred and more effecient method is to use decode() rather than decodeToString() and have an appropriate contentHandler deal with the decoded data.
public decodeToString ( string $wbxml ) : string
$wbxml string The WBXML document to decode.
return string The decoded XML document.
    public function decodeToString($wbxml)
    {
        $this->_ch = new Horde_Xml_Wbxml_ContentHandler();
        $this->decode($wbxml);
        return $this->_ch->getOutput();
    }

Usage Example

Esempio n. 1
0
 public function testDecode()
 {
     if (!is_executable('/usr/bin/wbxml2xml')) {
         $this->markTestSkipped('/usr/bin/wbxml2xml is required for comparison tests.');
     }
     $decoder = new Horde_Xml_Wbxml_Decoder();
     foreach (glob(__DIR__ . '/../../../../doc/Horde/Xml/Wbxml/examples/*.wbxml') as $file) {
         $xml_ref = shell_exec('/usr/bin/wbxml2xml' . ' -m 0 -o - "' . $file . '" 2>/dev/null');
         $xml_ref = preg_replace(array('/<\\?xml version=\\"1\\.0\\"\\?><!DOCTYPE [^>]*>/', '|<([^>]+)/>|'), array('', '<$1></$1>'), $xml_ref);
         $xml = $decoder->decodeToString(file_get_contents($file));
         if (is_string($xml)) {
             // Ignore <?xml and <!DOCTYPE stuff.
             $xml = preg_replace('/<\\?xml version=\\"1\\.0\\"\\?><!DOCTYPE [^>]*>/', '', $xml);
             // Handle different mimetypes.
             $xml = str_replace('application/vnd.syncml-devinf+wbxml', 'application/vnd.syncml-devinf+xml', $xml);
         }
         $this->assertEquals(Horde_String::lower($xml_ref), Horde_String::lower($xml));
     }
 }