<?php

$temp_filename = dirname(__FILE__) . "/xmlwriter_set_indent_string_error.tmp";
$fp = fopen($temp_filename, "w");
fwrite($fp, "Hi");
fclose($fp);
$resource = xmlwriter_open_uri($temp_filename);
var_dump(xmlwriter_set_indent_string($resource));
Exemplo n.º 2
0
<?php

dl('xmlwriter.so');
$xw = xmlwriter_open_memory();
xmlwriter_set_indent($xw, 1);
$res = xmlwriter_set_indent_string($xw, ' ');
xmlwriter_start_document($xw, '1.0', 'UTF-8');
// A first element
xmlwriter_start_element_ns($xw, 'prefix', 'books', 'uri');
xmlwriter_start_attribute($xw, 'isbn');
/* Uncomment this line if you have libxml 2.6.17 or CVS version
 after 2005/02/22
 earlier versions segfault
*/
/*
xmlwriter_start_attribute_ns($xw, 'prefix', 'isbn', 'uri');
xmlwriter_end_attribute($xw);
*/
xmlwriter_end_attribute($xw);
xmlwriter_text($xw, 'book1');
xmlwriter_end_element($xw);
xmlwriter_end_document($xw);
$out = xmlwriter_output_memory($xw, 0);
echo $out;
Exemplo n.º 3
0
 private function process_request($request)
 {
     global $API_DOMAIN, $API_DOMAIN_DOT_SUFFIX;
     $app_id = $this->app_id;
     $method = $request['method'];
     $callback = false;
     $serialized_result = '';
     // Initialize result
     $result = array();
     // Fix method name
     if (starts_with($method, $API_DOMAIN . '.')) {
         $method = substr($method, 9);
     }
     // Replace periods with underscores in method name
     $method_underscore = str_replace('.', '_', $method);
     $ec = $this->check_throttle($method_underscore, $request);
     if ($ec !== API_EC_SUCCESS) {
         $msg = $api_error_descriptions[$ec];
         if ($ec === API_EC_BAD_IP) {
             $msg .= ' (ip was: ' . $_SERVER['REMOTE_ADDR'] . ')';
         }
         throw new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $msg));
     }
     $impl = new FacebookApi10Implementation($app_id, $this->user_id, $this->session_key, $this->format);
     $api = new FacebookApi10Rest($impl);
     // Check that the method is valid
     if (!method_exists($api, $method_underscore) || !method_exists($impl, $method_underscore) || !api_can_call_method($app_id, $method_underscore)) {
         $ec = api10_FacebookApiErrorCode::API_EC_METHOD;
         throw new api10_FacebookApiException(array('error_code' => $ec, 'error_msg' => $GLOBALS['api_error_descriptions'][$ec]));
     } else {
         // Call the method and catch any exceptions
         $result = $api->{$method_underscore}($request);
     }
     switch ($this->format) {
         case 'manual':
             print api_xml_render_manual_error($ec, $msg, $request);
             break;
         case 'xml':
             // Prepare the XML response
             $xml_memory = xmlwriter_open_memory();
             xmlwriter_set_indent($xml_memory, true);
             xmlwriter_set_indent_string($xml_memory, '  ');
             xmlwriter_start_document($xml_memory, API_VERSION_10, 'UTF-8');
             if ($result instanceof Exception) {
                 $name = 'error_response';
             } else {
                 $name = $method_underscore . '_response';
             }
             $attrs = array();
             // FBOPEN:NOTE here, if you are not publishing your own .xsd, to use 'facebook.com' instead
             // of $API_DOMAIN_DOT_SUFFIX
             $attrs['xmlns'] = 'http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . API_VERSION_10 . '/';
             $attrs['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
             if ($method_underscore != 'fql_query') {
                 $attrs['xsi:schemaLocation'] = 'http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . API_VERSION_10 . '/ http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . API_VERSION_10 . '/facebook.xsd';
             }
             if (is_array($result) && isset($result[0]) && $result[0] instanceof xml_element) {
                 $attrs['list'] = 'true';
                 api_xml3_render_object($xml_memory, new xml_element($name, $result, $attrs));
             } else {
                 api_xml2_render_object($xml_memory, $name, $result, $attrs);
             }
             xmlwriter_end_document($xml_memory);
             // Write XML response
             $xml = xmlwriter_output_memory($xml_memory, true);
             if ($callback) {
                 $xml = addslashes($xml);
                 $xml = str_replace("\n", '\\n', $xml);
                 $serialized_result = $callback . '(\'' . $xml . '\');';
             } else {
                 $serialized_result = $xml;
             }
             break;
         case 'json':
             $json = api_json2_render_object($result);
             if ($callback) {
                 $serialized_result = $callback . '(' . $json . ');';
             } else {
                 $serialized_result = $json;
             }
             break;
     }
     return $serialized_result;
 }
 /**
  * Make XML document using built-in XMLWriter functionality
  * @return string
  */
 function makeXML_XMLWriter()
 {
     // XMLWriter object instance
     $this->xml = xmlwriter_open_memory();
     // Indentation
     xmlwriter_set_indent($this->xml, $this->indent);
     xmlwriter_set_indent_string($this->xml, $this->indent_string);
     // XML Document declaration
     xmlwriter_start_document($this->xml, '1.0', $this->encoding, 'yes');
     // <ROOT>
     xmlwriter_start_element($this->xml, $this->root_name);
     // <header>
     xmlwriter_start_element($this->xml, 'header');
     // <service>
     xmlwriter_start_element($this->xml, 'service');
     $this->xmlwriter_write_cdata($this->header_service);
     xmlwriter_end_element($this->xml);
     // </service>
     // <status>
     xmlwriter_start_element($this->xml, 'status');
     $this->xmlwriter_write_cdata($this->header_status);
     xmlwriter_end_element($this->xml);
     // </status>
     // <message>
     xmlwriter_start_element($this->xml, 'message');
     $this->xmlwriter_write_cdata($this->header_message);
     xmlwriter_end_element($this->xml);
     // </message>
     xmlwriter_end_element($this->xml);
     // </header>
     // <data>
     xmlwriter_start_element($this->xml, 'data');
     $this->dataElement($this->xml_data, '');
     xmlwriter_end_element($this->xml);
     // </data>
     if (!empty($this->debug_timers) && is_array($this->debug_timers)) {
         // <debug_timers>
         xmlwriter_start_element($this->xml, 'debug_timers');
         foreach ($this->debug_timers as $key => $val) {
             xmlwriter_start_element($this->xml, $key);
             $this->xmlwriter_write_cdata($val);
             xmlwriter_end_element($this->xml);
         }
         xmlwriter_end_element($this->xml);
         // </debug_timers>
     }
     xmlwriter_end_element($this->xml);
     // <ROOT>
     xmlwriter_end_document($this->xml);
     // Finish XML document
     // Generate XML string
     return xmlwriter_output_memory($this->xml, true);
 }
Exemplo n.º 5
0
    $result = $fax;
    $args = array();
    foreach ($request as $key => $val) {
        $args[] = new api10_arg(array('key' => $key, 'value' => $val));
    }
    $result->request_args = $args;
}
switch ($format) {
    case 'manual':
        print api_xml_render_manual_error($ec, $msg, $request);
        break;
    case 'xml':
        // Prepare the XML response
        $xml_memory = xmlwriter_open_memory();
        xmlwriter_set_indent($xml_memory, true);
        xmlwriter_set_indent_string($xml_memory, '  ');
        xmlwriter_start_document($xml_memory, API_VERSION_10, 'UTF-8');
        switch ($version) {
            case API_VERSION_10:
            default:
                if ($result instanceof Exception) {
                    $name = 'error_response';
                } else {
                    $name = $method_underscore . '_response';
                }
                $attrs = array();
                $attrs['xmlns'] = 'http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . $version . '/';
                $attrs['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
                if ($method_underscore != 'fql_query') {
                    $attrs['xsi:schemaLocation'] = 'http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . $version . '/ http://api.' . $API_DOMAIN_DOT_SUFFIX . '/' . $version . '/facebook.xsd';
                }
Exemplo n.º 6
0
<?php

$writer = xmlwriter_open_memory();
xmlwriter_set_indent_string($writer, '#');
// The second arg is supposedly required. But just keep executing anyway and use
// the previous value...
xmlwriter_set_indent_string($writer);
xmlwriter_set_indent($writer, true);
xmlwriter_start_document($writer, '1.0');
xmlwriter_start_element($writer, 'foo');
xmlwriter_start_element($writer, 'bar');
xmlwriter_end_element($writer);
xmlwriter_end_element($writer);
xmlwriter_end_document($writer);
var_dump(xmlwriter_output_memory($writer));
Exemplo n.º 7
0
function VS($x, $y)
{
    var_dump($x === $y);
    if ($x !== $y) {
        echo "Failed: {$y}\n";
        echo "got: {$x}\n";
    }
}
function VERIFY($x)
{
    VS($x, true);
}
$xml = xmlwriter_open_memory();
var_dump($xml);
VERIFY(xmlwriter_set_indent($xml, true));
VERIFY(xmlwriter_set_indent_string($xml, "  "));
VERIFY(xmlwriter_start_document($xml, "1.0", "utf-8"));
VERIFY(xmlwriter_start_element($xml, "node"));
VERIFY(xmlwriter_write_attribute($xml, "name", "value"));
VERIFY(xmlwriter_start_attribute($xml, "name2"));
VERIFY(xmlwriter_end_attribute($xml));
VERIFY(xmlwriter_write_element($xml, "subnode", "some text"));
VERIFY(xmlwriter_end_element($xml));
VERIFY(xmlwriter_start_element_ns($xml, "fb", "node", "http://www.facebook.com/"));
VERIFY(xmlwriter_write_attribute_ns($xml, "fb", "attr", "http://www.facebook.com/", "value"));
VERIFY(xmlwriter_start_attribute_ns($xml, "fb", "attr2", "http://www.facebook.com/"));
VERIFY(xmlwriter_end_attribute($xml));
VERIFY(xmlwriter_write_element_ns($xml, "prefix", "name", "http://some.url/", 1337));
VERIFY(xmlwriter_start_element($xml, "node"));
VERIFY(xmlwriter_full_end_element($xml));
VERIFY(xmlwriter_end_element($xml));