private function writeReaderImpl(XMLWriter $writer, XMLReader $reader) { switch ($reader->nodeType) { case XMLReader::ELEMENT: $writer->startElement($reader->name); if ($reader->moveToFirstAttribute()) { do { $writer->writeAttribute($reader->name, $reader->value); } while ($reader->moveToNextAttribute()); $reader->moveToElement(); } if ($reader->isEmptyElement) { $writer->endElement(); } break; case XMLReader::END_ELEMENT: $writer->endElement(); break; case XMLReader::COMMENT: $writer->writeComment($reader->value); break; case XMLReader::SIGNIFICANT_WHITESPACE: case XMLReader::TEXT: $writer->text($reader->value); break; case XMLReader::PI: $writer->writePi($reader->name, $reader->value); break; default: XMLReaderNode::dump($reader); } }
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); }
/** * 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; }
/** * @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; }
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(); }
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(); }
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(); }
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; }
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); }
/** * @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(); } }
public function finalize() { $this->xml->endElement(); //root element $this->xml->endDocument(); $this->xml->flush(); return $this->filename; }
public function finalize() { $this->writer->endElement(); $fragment = $this->contextNode->ownerDocument->createDocumentFragment(); $fragment->appendXML($this->writer->outputMemory()); $this->contextNode->parentNode->replaceChild($fragment, $this->contextNode); $this->finalized = true; }
/** * add number * * @param integer $_number * @param string $_type */ protected function _addNumber($_number, $_type) { $this->_writer->startElement("number"); $this->_writer->writeAttribute("type", $_type); $this->_writer->writeAttribute("quickdial", ""); $this->_writer->writeAttribute("vanity", ""); $this->_writer->writeAttribute("prio", ""); $this->_writer->text($_number); $this->_writer->endElement(); }
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); }
public function GenerateXMLResponse($session_ID, $status_array, $q_access_array = NULL, $associative_array = NULL, $section_name = NULL, $subsection_name = NULL) { $xml = new XMLWriter(); $xml->openMemory(); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement("IMS_RESPONSE"); $xml->startElement("SID"); $xml->text($session_ID); $xml->endElement(); $xml->startElement("STATUS"); $xml->startElement("STATUS_CODE"); $xml->text($status_array[0]); $xml->endElement(); $xml->startElement("STATUS_MESSAGE"); $xml->text($status_array[1]); $xml->endElement(); if (count($status_array) == 3) { $xml->startElement("RUN_LEVEL"); if ($status_array[2] == "1") { $xml->text("Edit Mode"); } else { $xml->text("View Mode"); } $xml->endElement(); } $xml->endElement(); if (!($q_access_array === NULL)) { $xml->startElement("QACCESS"); foreach ($q_access_array as $key => $data) { $xml->startElement(str_replace(' ', '', $key)); $xml->text(trim($data)); $xml->endElement(); } $xml->endElement(); } if (!($associative_array === NULL)) { $xml->startElement($section_name); foreach ($associative_array as $array_entry) { $xml->startElement($subsection_name); foreach ($array_entry as $key => $data) { $xml->startElement(str_replace(' ', '', $key)); $xml->text($data); $xml->endElement(); } $xml->endElement(); } $xml->endElement(); } $xml->endElement(); header("Content-type: text/xml"); echo $xml->outputMemory(true); }
/** * @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); }
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(); }
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); *****************************************************************/ }
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(); }
/** * 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(); }
public function addNotEmpty($node, \XMLWriter &$writer) { if (isset($node[$this->xsd_generator->getFullName('not_empty')]) && $node[$this->xsd_generator->getFullName('not_empty')]) { $writer->startElementNs('xsd', 'simpleType', null); $writer->startElementNs('xsd', 'restriction', null); $writer->writeAttribute('base', 'xsd:normalizedString'); $writer->startElementNs('xsd', 'minLength', null); $writer->writeAttribute('value', '200'); $writer->endElement(); $writer->endElement(); $writer->endElement(); return true; } return false; }
public function addNotEmpty($node, \XMLWriter &$writer) { if (isset($node[$this->xsd_generator->getFullName('not_empty')]) && $node[$this->xsd_generator->getFullName('not_empty')]) { $writer->startElementNs('xsd', 'simpleType', null); $writer->startElementNs('xsd', 'restriction', null); $writer->writeAttribute('base', 'xsd:decimal'); $writer->startElementNs('xsd', 'pattern', null); $writer->writeAttribute('value', '^[^0]*$'); $writer->endElement(); $writer->endElement(); $writer->endElement(); return true; } return false; }
function main() { $x = new XMLWriter(); $x->openMemory(); $x->setIndent(true); $x->startDocument('1.0'); $x->startElementNS(null, 'startNullPrefix', null); $x->startElementNS('', 'startEmptyPrefix', null); $x->writeElementNS(null, 'writeNullPrefix', null); $x->writeElementNS('', 'writeEmptyPrefix', null); $x->endElement(); $x->endElement(); $x->endDocument(); var_dump($x->outputMemory(true)); }
protected function getXmlLostCart(LostCart $lostCart) { $xml = new \XMLWriter(); $xml->openMemory(); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement("event"); if ($lostCart->getLostCartUrl()) { $xml->writeAttribute('RESTORE_CART_URL', $lostCart->getLostCartUrl()); // slevovy kupon $discountCoupon = $lostCart->getDiscountCoupon(); if ($discountCoupon instanceof Discount) { $xml->writeAttribute('COUPON_CODE', $discountCoupon->getCode()); $xml->writeAttribute('COUPON_VALUE', $discountCoupon->getValue()); $xml->writeAttribute('COUPON_VALIDITY', $this->dayToDate($discountCoupon->getValidityDay())); $xml->writeAttribute('COUPON_ORDER_VALUE', $discountCoupon->getMinOrderValue()); } } $xml->startElement("products"); foreach ($lostCart->getProducts() as $product) { $xml->startElement("product"); $xml->startElement("name"); $xml->writeCData($product->getName()); $xml->endElement(); $xml->startElement("url"); $xml->writeCData($product->getUrl()); $xml->endElement(); $xml->startElement("img"); $xml->writeCData($product->getImage()); $xml->endElement(); $xml->startElement("price-old"); $xml->writeCData($product->getPriceOld()); $xml->endElement(); $xml->startElement("price"); $xml->writeCData($product->getPrice()); $xml->endElement(); $xml->startElement("sale"); $xml->writeCData($product->getSale()); $xml->endElement(); $xml->startElement("buy-text"); $xml->writeCData($this->getBuyText()); $xml->endElement(); $xml->endElement(); } $xml->endElement(); $xml->endElement(); $xml->endDocument(); return $xml->flush(); }
/** * 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(); }
/** * Ends the last opened element. */ public function endElement() { if ($this->openElements) { $this->xml->endElement(); $this->openElements--; } }
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; }