Exemple #1
0
 /**
  * Generate a partial report for a single processed file.
  *
  * Function should return TRUE if it printed or stored data about the file
  * and FALSE if it ignored the file. Returning TRUE indicates that the file and
  * its data should be counted in the grand totals.
  *
  * @param array   $report      Prepared report data.
  * @param boolean $showSources Show sources?
  * @param int     $width       Maximum allowed line width.
  *
  * @return boolean
  */
 public function generateFileReport($report, $showSources = false, $width = 80)
 {
     $out = new XMLWriter();
     $out->openMemory();
     $out->setIndent(true);
     if ($report['errors'] === 0 && $report['warnings'] === 0) {
         // Nothing to print.
         return false;
     }
     $out->startElement('file');
     $out->writeAttribute('name', $report['filename']);
     foreach ($report['messages'] as $line => $lineErrors) {
         foreach ($lineErrors as $column => $colErrors) {
             foreach ($colErrors as $error) {
                 $error['type'] = strtolower($error['type']);
                 if (PHP_CODESNIFFER_ENCODING !== 'utf-8') {
                     $error['message'] = iconv(PHP_CODESNIFFER_ENCODING, 'utf-8', $error['message']);
                 }
                 $out->startElement('error');
                 $out->writeAttribute('line', $line);
                 $out->writeAttribute('column', $column);
                 $out->writeAttribute('severity', $error['type']);
                 $out->writeAttribute('message', $error['message']);
                 $out->writeAttribute('source', $error['source']);
                 $out->endElement();
             }
         }
     }
     //end foreach
     $out->endElement();
     echo $out->flush();
     return true;
 }
Exemple #2
0
 public function index()
 {
     $writter = new \XMLWriter();
     $writter->openMemory();
     $writter->startDocument('1.0', 'UTF-8');
     $writter->setIndent(TRUE);
     $writter->startElement('rss');
     $writter->writeAttribute('version', '2.0');
     $writter->startElement('channel');
     //header
     $writter->writeElement('title', 'phpMint RSS');
     $writter->writeElement('link', 'mein LINK');
     $writter->writeElement('description', 'Ein PHP-Blog über PHP, jQuery, JavaScript und weiteren Technik-Themen.');
     //body
     foreach ($this->getPosts() as $key => $post) {
         $writter->startElement('item');
         $writter->writeElement('title', $post['title']);
         $writter->writeElement('pubDate', $post['datum']);
         $writter->writeElement('link', $post['slug']);
         $writter->writeElement('description', $post['preview']);
         $writter->endElement();
     }
     while ($writter->endElement() !== false) {
         continue;
     }
     $writter->endDocument();
     $test = $writter->outputMemory(TRUE);
     $loger = new \Loger('session');
     $loger->write($test);
     $this->response->addHeader('Content-type: text/xml; charset=UTF-8');
     $this->response->setOutput($test);
 }
Exemple #3
0
 public function to_html($parent)
 {
     $w = new XMLWriter();
     $w->openMemory();
     $w->startElement('div');
     $w->writeAttribute('class', 'season');
     $w->startElement('div');
     $w->writeAttribute('class', 'season_name');
     $w->text("Saison " . $this->get_num());
     $w->endElement();
     $w->startElement('div');
     $w->writeAttribute('class', 'episode_container');
     $str = "";
     usort($this->episodes, 'wssub_cmp_num');
     foreach ($this->episodes as $ep) {
         if (!$ep->get_num()) {
             $this->log("Bad ep with no number: " . $ep->to_string(), 'warn');
             continue;
         }
         $str .= $ep->to_html($parent);
     }
     $w->writeRaw($str);
     $w->endElement();
     $w->endElement();
     return $w->flush();
 }
Exemple #4
0
 public function to_html($parent)
 {
     if (!$this->get_lang()) {
         $this->log("to_html() no lang", 'error');
         return null;
     }
     if (!$this->get_id()) {
         $this->log("to_html() no id", 'error');
         return null;
     }
     if (!$parent->get_request()->is_lang_ok($this->get_lang())) {
         return null;
     }
     $w = new XMLWriter();
     $w->openMemory();
     $w->startElement('div');
     $w->writeAttribute('class', 'subtitle');
     $w->startElement('a');
     $w->writeAttribute('class', 'subtitle_href');
     $w->writeAttribute('href', $parent->get_prefix_url() . '/download-' . $this->get_id() . '.html');
     $w->startElement('img');
     $w->writeAttribute('class', 'subtitle_lang');
     $w->writeAttribute('src', $parent->get_prefix_url() . '/images/flags/' . $this->get_lang() . '.gif');
     $w->endElement();
     $w->endElement();
     $w->endElement();
     return $w->flush();
 }
 function impersonate_login($admin_user, $admin_pass, $site, $user)
 {
     //create a new xmlwriter object
     $xml = new XMLWriter();
     //using memory for string output
     $xml->openMemory();
     //set the indentation to true (if false all the xml will be written on one line)
     $xml->setIndent(true);
     //create the document tag, you can specify the version and encoding here
     $xml->startDocument();
     //Create an element
     $xml->startElement("tsRequest");
     $xml->startElement("credentials");
     $xml->writeAttribute("name", $admin_user);
     $xml->writeAttribute("password", $admin_pass);
     $xml->startElement("site");
     $xml->writeAttribute("contentUrl", strtoupper($site));
     $xml->endElement();
     //close contentUrl
     $xml->startElement("user");
     $xml->writeAttribute("id", $user);
     $xml->endElement();
     //close user
     $xml->endElement();
     //close credentials
     $xml->endElement();
     //close tsRequest
     return $data_string = $xml->outputMemory();
 }
Exemple #6
0
 private function writeCommon(\XMLWriter $writer, Common $common)
 {
     if ($common->getAuthor()) {
         $writer->startElement('itunes:author');
         $writer->writeCdata($common->getAuthor());
         $writer->endElement();
     }
     if ($common->getSummary()) {
         $writer->startElement('itunes:summary');
         $writer->writeCdata($common->getSummary());
         $writer->endElement();
     }
     if ($common->getBlock()) {
         $writer->writeElement('itunes:block', 'Yes');
     }
     if ($common->getImage()) {
         $writer->startElement('itunes:image');
         $writer->writeAttribute('href', $common->getImage());
         $writer->endElement();
     }
     $writer->writeElement('itunes:explicit', true === $common->getExplicit() ? 'Yes' : 'No');
     if ($common->getSubtitle()) {
         $writer->startElement('itunes:subtitle');
         $writer->writeCdata($common->getSubtitle());
         $writer->endElement();
     }
 }
 public function creaXml()
 {
     $writer = new XMLWriter();
     //$writer->setIndent(true);
     $csc = 1;
     $writer->openMemory();
     $writer->startDocument();
     $writer->startElement("ROOT");
     while (!$this->rs->EOF) {
         $writer->startElement("registro");
         $writer->startElement("CSC");
         $writer->text($csc);
         $writer->endElement();
         for ($x = 0; $x < $this->rs->FieldCount(); $x++) {
             $fld = $this->rs->FetchField($x);
             $writer->startElement(strtoupper($fld->name));
             $writer->text($this->rs->fields[strtoupper($fld->name)]);
             $writer->endElement();
         }
         $writer->endElement();
         $this->rs->MoveNext();
         $csc++;
     }
     $writer->endElement();
     $writer->endDocument();
     $algo = $writer->outputMemory(true);
     return $algo;
 }
Exemple #8
0
 public function to_html($parent)
 {
     $w = new XMLWriter();
     $w->openMemory();
     $w->startElement('div');
     $w->writeAttribute('class', 'show');
     $w->startElement('a');
     $w->writeAttribute('class', 'name');
     $w->writeAttribute('href', $parent->get_prefix_url() . $this->get_href());
     $w->text($this->get_name());
     $w->endElement();
     $img = null;
     if ($img = $this->get_img()) {
         $w->startElement('img');
         $w->writeAttribute('src', $parent->get_prefix_url() . $img);
         $w->writeAttribute('alt', $this->get_name());
         $w->endElement();
     }
     $str = "";
     $w->startElement('div');
     $w->writeAttribute('class', 'season_container');
     usort($this->seasons, 'wssub_cmp_num');
     foreach ($this->get_seasons() as $season) {
         if (!$season) {
             $this->log('to_html: "empty season', 'warn');
         }
         $str .= $season->to_html($parent);
     }
     $w->writeRaw($str);
     $w->endElement();
     $w->endElement();
     return $w->flush();
 }
 /**
  * @param $ticket
  */
 private function generateTicket($ticket)
 {
     $this->ticket = $ticket;
     $this->writeSingleElement('key');
     $this->writeSingleElement('reporter');
     $this->writeSingleElement('issueType');
     $this->writeImagePathElement();
     $this->writeSingleElement('sprint');
     $this->writeSingleElement('summary');
     $this->writeSingleElement('devTeam');
     $this->writeSingleElement('hasSubTasks');
     $this->writeSingleElement('storyPoints');
     if (isset($this->ticket['epicData'])) {
         $this->buffer->startElement('epic');
         $this->buffer->writeElement('key', $this->ticket['epicData']['key']);
         $this->buffer->writeElement('summary', $this->ticket['epicData']['summary']);
         $this->buffer->endElement();
     }
     if (isset($this->ticket['parentData'])) {
         $this->buffer->startElement('parent');
         $this->buffer->writeElement('key', $this->ticket['epicData']['key']);
         $this->buffer->writeElement('summary', $this->ticket['epicData']['summary']);
         $this->buffer->endElement();
     }
 }
Exemple #10
0
 public function getInfoByCode($user = '', $pass = '', $code = '')
 {
     //用户检查
     $action = new CodeInfo();
     if ($code) {
         $result = $action->getInfoByCodeFormMySystem($code);
     }
     $xw = new XMLWriter();
     $xw->openMemory();
     $xw->startDocument('1.0', 'gb2312');
     //版本與編碼
     $xw->startElement('packet');
     if ($result) {
         $xw->writeElement('result', 'true');
     } else {
         $xw->writeElement('result', 'false');
     }
     //查询条码失败
     $fields = array("code", "factoryNo", "goodsName", "spec", "current1", "voltage1", "direct", "constant", "grade", "madeIn", "madeDate");
     if ($result) {
         $xw->startElement('codeInfo');
         foreach ($result as $key => $value) {
             if (!is_bool(array_search($key, $fields))) {
                 $xw->writeElement($key, $value);
             }
         }
         $xw->endElement('codeInfo');
     }
     $xw->endElement('packet');
     return $xw->outputMemory(true);
 }
 /**
  * @param string $fileToSave
  * @param number $offsetStart
  * @param number $limit
  * @param null | string $suffix
  *
  * @return string
  */
 protected function saveToFile($fileToSave, $offsetStart, $limit, $suffix = null)
 {
     $writer = new \XMLWriter();
     $path = pathinfo($fileToSave);
     $filePath = $path['dirname'] . '/' . $path['filename'];
     if (!is_null($suffix)) {
         $filePath .= self::SEPERATOR . $suffix;
     }
     if (empty($path['extension'])) {
         $filePath .= self::XML_EXT;
     } else {
         $filePath .= '.' . $path['extension'];
     }
     $writer->openURI($filePath);
     $writer->startDocument('1.0', 'UTF-8');
     $writer->setIndent(true);
     $writer->startElement('sitemapindex');
     $writer->writeAttribute('xmlns', self::SCHEMA);
     for ($i = $offsetStart; $i < count($this->items) && $i < $limit; $i++) {
         $item = $this->items[$i];
         $writer->startElement('sitemap');
         $writer->writeElement('loc', $item['url']);
         $writer->writeElement('lastmod', $item['modified']->format(ModifiableInterface::MODIFIED_DATE_FORMAT));
         $writer->endElement();
     }
     $writer->endElement();
     $writer->endDocument();
     return $filePath;
 }
 public function addTest($test)
 {
     if ($this->finalized) {
         throw new PHP_CodeCoverage_RuntimeException('Coverage Report already finalized');
     }
     $this->writer->startElement('covered');
     $this->writer->writeAttribute('by', $test);
     $this->writer->endElement();
 }
Exemple #13
0
 public function toXml(XMLWriter $x)
 {
     $x->writeElement('url', $this->_url);
     $x->startElement('params');
     foreach ($this->_params as $k => $v) {
         $x->startElement('param');
         $x->writeAttribute('name', $k);
         $x->text($v);
         $x->endElement();
     }
     $x->endElement();
 }
 protected function doProcess($inputPath, $outputPath)
 {
     $sitemap = Yaml::parse(file_get_contents($inputPath));
     if (!isset($sitemap['locations'])) {
         throw new PieCrustException("No locations were defined in the sitemap.");
     }
     $xml = new \XMLWriter();
     $xml->openMemory();
     $xml->setIndent(true);
     $xml->startDocument('1.0', 'utf-8');
     $xml->startElement('urlset');
     $xml->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     foreach ($sitemap['locations'] as $loc) {
         $xml->startElement('url');
         // loc
         $locUrl = $this->pieCrust->getConfig()->getValueUnchecked('site/root') . ltrim($loc['url'], '/');
         $xml->writeElement('loc', $locUrl);
         // lastmod
         $locLastMod = null;
         if (isset($loc['lastmod'])) {
             $locLastMod = $loc['lastmod'];
         } else {
             if (isset($loc['lastmod_path'])) {
                 $fullPath = $this->pieCrust->getRootDir() . ltrim($loc['lastmod_path'], '/\\');
                 $locLastMod = date('c', filemtime($fullPath));
             } else {
                 $urlInfo = UriParser::parseUri($this->pieCrust, $loc['url']);
                 if ($urlInfo) {
                     if (is_file($urlInfo['path'])) {
                         $locLastMod = date('c', filemtime($urlInfo['path']));
                     }
                 }
             }
         }
         if (!$locLastMod) {
             throw new PieCrustException("No idea what '" . $loc['url'] . "' is. Please specify a 'lastmod' time, or 'lastmod_path' path.");
         }
         $xml->writeElement('lastmod', $locLastMod);
         // changefreq
         if (isset($loc['changefreq'])) {
             $xml->writeAttribute('changefreq', $loc['changefreq']);
         }
         // priority
         if (isset($loc['priority'])) {
             $xml->writeAttribute('priority', $loc['priority']);
         }
         $xml->endElement();
     }
     $xml->endElement();
     $xml->endDocument();
     $markup = $xml->outputMemory(true);
     file_put_contents($outputPath, $markup);
 }
Exemple #15
0
 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
 {
     $writer->startElement('array');
     $writer->startElement('data');
     foreach ($this->value as $val) {
         $writer->startElement('value');
         $val->write($writer, $timezone, $stringTag);
         $writer->endElement();
     }
     $writer->endElement();
     $writer->endElement();
 }
 /**
  * Gets a list of comments by
  * 
  * @param string status - List comments by status.
  * @param string response_type - XML or JSON
  * 
  * @return array
  */
 private function _get_comment_list($where, $limit = '', $response_type)
 {
     $xml = new XMLWriter();
     $json = array();
     $json_item = array();
     $this->query = "SELECT * FROM comment {$where} {$limit}";
     $this->items = $this->db->query($this->query);
     if ($response_type == "xml") {
         $xml->openMemory();
         $xml->startDocument('1.0', 'UTF-8');
         $xml->startElement('response');
         $xml->startElement('payload');
         $xml->writeElement('domain', $this->domain);
         $xml->startElement('comments');
     }
     foreach ($this->items as $list_item) {
         if ($response_type == "json") {
             $json_item = (array) $list_item;
         } else {
             $xml->startElement('comment');
             $xml->writeElement('id', $list_item->id);
             $xml->writeElement('incident_id', $list_item->incident_id);
             $xml->writeElement('user_id', $list_item->user_id);
             $xml->writeElement('comment_author', $list_item->comment_author);
             $xml->writeElement('comment_email', $list_item->comment_email);
             $xml->writeElement('comment_description', $list_item->comment_description);
             $xml->writeElement('comment_ip', $list_item->comment_ip);
             $xml->writeElement('comment_rating', $list_item->comment_spam);
             $xml->writeElement('comment_active', $list_item->comment_active);
             $xml->writeElement('comment_date', $list_item->comment_date);
             $xml->endElement();
             // comment
         }
     }
     if ($response_type == "xml") {
         $xml->endElement();
         // comments
         $xml->endElement();
         // payload
         $xml->startElement('error');
         $xml->writeElement('code', 0);
         $xml->writeElement('message', 'No Error');
         $xml->endElement();
         //end error
         $xml->endElement();
         // end response
         return $xml->outputMemory(true);
     } else {
         $json = array("payload" => array("comments" => $json_item));
         return $this->api_actions->_array_as_JSON($json);
     }
 }
Exemple #17
0
 public function to_html($parent)
 {
     $w = new XMLWriter();
     $w->openMemory();
     $w->startElement('div');
     $w->writeAttribute('class', 'log_message');
     $w->startElement('div');
     $w->writeAttribute('class', 'log_message_' . $this->type);
     $w->writeRaw('<div class="log_class">' . $this->class . '</div>::<div class="log_msg">' . $this->msg . '</div>');
     $w->endElement();
     $w->endElement();
     return $w->flush();
 }
Exemple #18
0
 /**
  * @inheritdoc
  */
 public function encode()
 {
     $writer = new \XMLWriter();
     $writer->openMemory();
     $writer->startElement("DATOSENTRADA");
     foreach ($this->all() as $name => $value) {
         $writer->startElement($name);
         $writer->text($value);
         $writer->endElement();
     }
     $writer->endElement();
     return $writer->outputMemory(true);
 }
function GetProjectDetail($projId)
{
    //Return metadata about the columns in each table for a given database (table_schema)
    $qry = "SELECT id, p_name, p_details FROM tb_projects where id = " . $projId;
    date_default_timezone_set('Australia/Sydney');
    error_log("In project_get_detail.php...\n" . $qry);
    $dbConn = opendatabase();
    $result = mysqli_query($dbConn, $qry);
    date_default_timezone_set('Australia/Sydney');
    error_log("Records in Projects: " . mysqli_num_rows($result));
    if (!$result || mysqli_num_rows($result) <= 0) {
        echo "Could not obtain metadata information.";
        return false;
    }
    /*****************************************************************/
    $xml = new XMLWriter();
    //$projXml  = new DOMDocument();
    //$xml->openURI("php://output");
    $xml->openMemory();
    $xml->startDocument();
    $xml->setIndent(true);
    $xml->startElement("projects");
    while ($row = mysqli_fetch_assoc($result)) {
        $xml->startElement("project");
        $xml->writeAttribute('id', $projId);
        $xml->writeRaw($row['p_name']);
        $xml->endElement();
        $xml->startElement("project_details");
        $xml->startCData("details");
        $xml->writeRaw($row['p_details']);
        $xml->endCData();
        $xml->endElement();
    }
    $xml->endElement();
    $xml->endDocument();
    $dbConn->close();
    header('Content-type: text/xml');
    $strXML = $xml->outputMemory(TRUE);
    $xml->flush();
    date_default_timezone_set('Australia/Sydney');
    error_log("String XML:\n " . $strXML);
    //$projXml->loadXML($strXML);
    echo $strXML;
    /*****************************************************************
    	$options = array();
    	while ($row = mysqli_fetch_assoc($result)){
    		$options['object_row'][] = $row;
    	}
    	echo json_encode($options);
    	*****************************************************************/
}
Exemple #20
0
 /**
  * Construct the record in XMLWriter
  *
  * @return null
  */
 public function build()
 {
     $this->xmlWriter->startElement($this->tagName);
     // Simple required elements
     foreach ($this->simpleValues as $tag => $method) {
         $this->xmlWriter->writeElement($tag, $this->record->{$method}());
     }
     foreach ($this->optionalSimpleValues as $tag => $method) {
         $value = $this->record->{$method}();
         if (!empty($value)) {
             $this->xmlWriter->writeElement($tag, $value);
         }
     }
     foreach ($this->complexValues as $generatorClass => $method) {
         $value = $this->record->{$method}();
         if ($value) {
             /** @var Record $generator */
             $generator = new $generatorClass();
             $generator->setXmlWriter($this->xmlWriter);
             $generator->setRecord($value);
             $generator->build();
         }
     }
     foreach ($this->complexValueSets as $tag => $complex) {
         $this->xmlWriter->startElement($tag);
         $method = $complex['values'];
         // getter method, should return an array
         $generatorClass = $complex['generator'];
         // Should be a subclass of BeerXML\Generator\Record
         $values = $this->record->{$method}();
         $generator = new $generatorClass();
         $generator->setXmlWriter($this->xmlWriter);
         foreach ($values as $record) {
             $generator->setRecord($record);
             $generator->build();
         }
         $this->xmlWriter->endElement();
     }
     // If the given record implements the interface for the display fields, write those too
     if ($this->record instanceof $this->displayInterface) {
         foreach ($this->displayValues as $tag => $method) {
             $value = $this->record->{$method}();
             if (!empty($value)) {
                 $this->xmlWriter->writeElement($tag, $value);
             }
         }
     }
     // Call the parser to allow it to add any other weird fields
     $this->additionalFields();
     $this->xmlWriter->endElement();
 }
Exemple #21
0
 public function toXml(XMLWriter $x)
 {
     $x->startElement('template');
     $x->text($this->_template);
     $x->endElement();
     $x->startElement('params');
     foreach ($this->getVars() as $k => $v) {
         $x->startElement('param');
         $x->writeAttribute('name', $k);
         $x->text($v);
         $x->endElement();
     }
     $x->endElement();
 }
 /**
  * Start Generating EDMX file.
  *
  * @return EDMX xml object.
  */
 public function saveConnectionParams()
 {
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::CONNECTION_PARAMS);
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::HOST);
     $this->xmlWriter->text($this->connectionParams['host']);
     $this->xmlWriter->endElement();
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::PORT);
     if (isset($this->connectionParams['port'])) {
         $this->xmlWriter->text($this->connectionParams['port']);
     }
     $this->xmlWriter->endElement();
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::DATABASE);
     $this->xmlWriter->text($this->connectionParams['dbname']);
     $this->xmlWriter->endElement();
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::USER);
     $this->xmlWriter->text($this->connectionParams['user']);
     $this->xmlWriter->endElement();
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::PASSWORD);
     $this->xmlWriter->text($this->connectionParams['password']);
     $this->xmlWriter->endElement();
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::SERVICE);
     $this->xmlWriter->text($this->connectionParams['serviceName']);
     $this->xmlWriter->endElement();
     $this->xmlWriter->endElement();
     return $this->xmlWriter->outputMemory(true);
 }
Exemple #23
0
/**
 * Create RSS Feed
 * @param entries
 * @param config
 */
function create_rss($entries, $config)
{
    // Inspired from http://www.phpntips.com/xmlwriter-2009-06/
    $xml = new XMLWriter();
    // Output directly to the user
    $xml->openURI('php://output');
    $xml->startDocument('1.0');
    $xml->setIndent(2);
    //rss
    $xml->startElement('rss');
    $xml->writeAttribute('version', '2.0');
    $xml->writeAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
    //channel
    $xml->startElement('channel');
    // title, desc, link, date
    $xml->writeElement('title', $config['title']);
    // $xml->writeElement('description', $config['description']);
    // $xml->writeElement('link', 'http://www.example.com/rss.hml');
    $xml->writeElement('pubDate', date('r'));
    if (!empty($entries)) {
        foreach ($entries as $entry) {
            // item
            $xml->startElement('item');
            $xml->writeElement('title', $entry->title);
            if (isset($entry->permalink)) {
                $xml->writeElement('link', $entry->permalink);
            }
            $xml->startElement('description');
            $xml->writeCData($entry->content);
            $xml->endElement();
            $xml->writeElement('pubDate', date('r', strtotime($entry->date)));
            // category
            // $xml->startElement('category');
            // $xml->writeAttribute('domain', 'http://www.example.com/cat1.htm');
            // $xml->text('News');
            // $xml->endElement();
            // end item
            $xml->endElement();
        }
    }
    // end channel
    $xml->endElement();
    // end rss
    $xml->endElement();
    // end doc
    $xml->endDocument();
    // flush
    $xml->flush();
}
Exemple #24
0
 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
 {
     $writer->startElement('struct');
     foreach ($this->value as $key => $val) {
         $writer->startElement('member');
         $writer->startElement('name');
         $writer->text((string) $key);
         $writer->endElement();
         $writer->startElement('value');
         $val->write($writer, $timezone, $stringTag);
         $writer->endElement();
         $writer->endElement();
     }
     $writer->endElement();
 }
 /**
  * Recursive function for processing nested arrays.
  *
  * @param array $array
  * @param null  $parentName name of parent node
  */
 protected function fromArray(array $array, $parentName = null)
 {
     foreach ($array as $name => $value) {
         if ($newName = $this->mapName($parentName)) {
             $this->xmlWriter->startElement($newName);
         } else {
             $this->xmlWriter->startElement($name);
         }
         if (is_array($value)) {
             $this->fromArray($value, $name);
         } elseif (!zbx_empty($value)) {
             $this->xmlWriter->text($value);
         }
         $this->xmlWriter->endElement();
     }
 }
 public function write(RestrictionInterface $restriction, \XMLWriter $xmlWriter)
 {
     $xmlWriter->startElement('video:restriction');
     $xmlWriter->writeAttribute('relationship', $restriction->relationship());
     $xmlWriter->text(implode(' ', $restriction->countryCodes()));
     $xmlWriter->endElement();
 }
 public function setElementFromArray(XMLWriter $xml, $rootNode, array $config)
 {
     $config = $this->normalize($config);
     if (!empty($config)) {
         foreach ($config as $key => $val) {
             $numeric = 0;
             if (is_numeric($key)) {
                 $numeric = 1;
                 $key = $rootNode;
             }
             if (is_array($val)) {
                 $isAssoc = $this->isAssoc($val);
                 if ($isAssoc || $numeric) {
                     $xml->startElement($key);
                 }
                 $this->setElementFromArray($xml, $key, $val);
                 if ($isAssoc || $numeric) {
                     $xml->endElement();
                 }
                 continue;
             }
             $xml->writeElement($key, $val);
         }
     }
 }
 /**
  * Takes an array and produces XML based on it.
  *
  * @param XMLWriter $xmlw       XMLWriter object that was previously instanted
  * and is used for creating the XML.
  * @param array     $data       Array to be converted to XML.
  * @param string    $defaultTag Default XML tag to be used if none specified.
  * 
  * @return void
  */
 private function _arr2xml(\XMLWriter $xmlw, $data, $defaultTag = null)
 {
     foreach ($data as $key => $value) {
         if ($key === Resources::XTAG_ATTRIBUTES) {
             foreach ($value as $attributeName => $attributeValue) {
                 $xmlw->writeAttribute($attributeName, $attributeValue);
             }
         } else {
             if (is_array($value)) {
                 if (!is_int($key)) {
                     if ($key != Resources::EMPTY_STRING) {
                         $xmlw->startElement($key);
                     } else {
                         $xmlw->startElement($defaultTag);
                     }
                 }
                 $this->_arr2xml($xmlw, $value);
                 if (!is_int($key)) {
                     $xmlw->endElement();
                 }
             } else {
                 $xmlw->writeElement($key, $value);
             }
         }
     }
 }
Exemple #29
0
 private function startElement(Shape $shape, $name, \XMLWriter $xml)
 {
     $xml->startElement($name);
     if ($ns = $shape['xmlNamespace']) {
         $xml->writeAttribute(isset($ns['prefix']) ? "xmlns:{$ns['prefix']}" : 'xmlns', $shape['xmlNamespace']['uri']);
     }
 }
Exemple #30
-11
 public static function Encode($requestObject)
 {
     $soap = "";
     try {
         $writer = new XMLWriter();
         $writer->openMemory();
         $writer->startDocument();
         $writer->setIndent(4);
         $writer->startElement("soap:Envelope");
         $writer->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
         $writer->writeAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
         $writer->writeAttribute("xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/");
         $writer->startElement("soap:Body");
         $options = array(XML_SERIALIZER_OPTION_INDENT => '    ', XML_SERIALIZER_OPTION_LINEBREAKS => "\n", XML_SERIALIZER_OPTION_DEFAULT_TAG => '', XML_SERIALIZER_OPTION_TYPEHINTS => false, XML_SERIALIZER_OPTION_IGNORE_NULL => true, XML_SERIALIZER_OPTION_CLASSNAME_AS_TAGNAME => true);
         $serializer = new XML_Serializer($options);
         $result = $serializer->serialize($requestObject);
         if ($result === true) {
             $xml = $serializer->getSerializedData();
             $xml = str_replace('<>', '', $xml);
             $xml = str_replace('</>', '', $xml);
         }
         $writer->writeRaw($xml);
         $writer->endElement();
         $writer->endElement();
         $writer->endDocument();
         $soap = $writer->flush();
         $soap = str_replace("<?xml version=\"1.0\"?>", "", $soap);
     } catch (Exception $ex) {
         throw new Exception("Error occurred while Soap encoding");
     }
     return $soap;
 }