/** * Create new XMLWriter * * @param int $tempLocation Temporary storage location * @param string $tempFolder Temporary storage folder */ public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder = './') { // Create internal XMLWriter $this->xmlWriter = new \XMLWriter(); // Open temporary storage if ($tempLocation == self::STORAGE_MEMORY) { $this->xmlWriter->openMemory(); } else { // Create temporary filename $this->tempFile = @tempnam($tempFolder, 'xml'); // Fallback to memory when temporary file cannot be used // @codeCoverageIgnoreStart // Can't find any test case. Uncomment when found. if ($this->xmlWriter->openUri($this->tempFile) === false) { $this->xmlWriter->openMemory(); } // @codeCoverageIgnoreEnd } // Set xml Compatibility $compatibility = Settings::hasCompatibility(); if ($compatibility) { $this->xmlWriter->setIndent(false); $this->xmlWriter->setIndentString(''); } else { $this->xmlWriter->setIndent(true); $this->xmlWriter->setIndentString(' '); } }
protected function setupStoreData() { // Using XMLWriter because SimpleXML namespaces on attribute names $this->doc = new XMLWriter(); $this->doc->openMemory(); $this->doc->setIndent(true); $this->doc->setIndentString(' '); $this->doc->startDocument('1.0', 'UTF-8'); $this->doc->startElement('feed'); $this->doc->writeAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $this->doc->writeAttribute('xmlns:g', 'http://base.google.com/ns/1.0'); $this->doc->writeElement('title', $this->getConfig('title')); $this->doc->startElement('link'); $this->doc->writeAttribute('rel', 'self'); $this->doc->writeAttribute('href', $this->_store->getBaseUrl()); $this->doc->endElement(); $date = new Zend_Date(); $this->doc->writeElement('updated', $date->get(Zend_Date::ATOM)); $this->doc->startElement('author'); $this->doc->writeElement('name', $this->getConfig('author')); $this->doc->endElement(); $url = $this->_store->getBaseUrl(); $day = $date->toString('yyyy-MM-dd'); $path = $this->getConfig('output'); $filename = $path . '/' . str_replace('+', '-', strtolower(urlencode($this->_store->getName()))) . '-products.xml'; $this->doc->writeElement('id', 'tag:' . $url . ',' . $day . ':' . $filename); }
/** * Create new XMLWriter * * @param int $tempLocation Temporary storage location * @param string $tempFolder Temporary storage folder */ public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder = './') { // Create internal XMLWriter $this->xmlWriter = new \XMLWriter(); // Open temporary storage if ($tempLocation == self::STORAGE_MEMORY) { $this->xmlWriter->openMemory(); } else { // Create temporary filename $this->tempFile = @tempnam($tempFolder, 'xml'); // Open storage if ($this->xmlWriter->openUri($this->tempFile) === false) { // Fallback to memory... $this->xmlWriter->openMemory(); } } // Set xml Compatibility $compatibility = Settings::getCompatibility(); if ($compatibility) { $this->xmlWriter->setIndent(false); $this->xmlWriter->setIndentString(''); } else { $this->xmlWriter->setIndent(true); $this->xmlWriter->setIndentString(' '); } }
/** * Create a new PHPPowerPoint_Shared_XMLWriter instance * * @param int $pTemporaryStorage Temporary storage location * @param string $pTemporaryStorageFolder Temporary storage folder */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') { // Create internal XMLWriter $this->_xmlWriter = new XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->_xmlWriter->openMemory(); } else { // Create temporary filename $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml'); // Open storage if ($this->_xmlWriter->openUri($this->_tempFileName) === false) { // Fallback to memory... $this->_xmlWriter->openMemory(); } } // Set default values // proposed to be false in production version $this->_xmlWriter->setIndent(true); //$this->_xmlWriter->setIndent(false); // Set indent // proposed to be '' in production version $this->_xmlWriter->setIndentString(' '); //$this->_xmlWriter->setIndentString(''); }
/** * Constructor * * @param PMF_Faq $faq PMF_Faq object * @param PMF_Category $category PMF_Category object * * return PMF_Export_Xhtml */ public function __construct(PMF_Faq $faq, PMF_Category $category) { $this->faq = $faq; $this->category = $category; $this->xml = new XMLWriter(); $this->xml->openMemory(); $this->xml->setIndent(true); }
/** * Fetches the site with the given name and exports it into XML. * * @param array<Site> $sites * @param boolean $tidy Whether to export formatted XML * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "TYPO3.Neos:Page", "!TYPO3.Neos:Page,TYPO3.Neos:Text") * @return string */ public function export(array $sites, $tidy = false, $nodeTypeFilter = null) { $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openMemory(); $this->xmlWriter->setIndent($tidy); $this->exportSites($sites, $nodeTypeFilter); return $this->xmlWriter->outputMemory(true); }
/** * Fetches the site with the given name and exports it into XML. * * @param array<Site> $sites * @param boolean $tidy Whether to export formatted XML * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "TYPO3.Neos:Page", "!TYPO3.Neos:Page,TYPO3.Neos:Text") * @return string */ public function export(array $sites, $tidy = FALSE, $nodeTypeFilter = NULL) { $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openMemory(); $this->xmlWriter->setIndent($tidy); $this->exportSites($sites, $nodeTypeFilter); return $this->xmlWriter->outputMemory(TRUE); }
/** * Set and instantiate new UTF-8 XML document */ public function __construct() { $this->context = new \XMLWriter(); $this->context->openMemory(); $this->context->startDocument('1.0', 'UTF-8'); $this->context->setIndent(true); $this->context->setIndentString(" "); }
public function __construct(DOMElement $context, $line) { $this->contextNode = $context; $this->writer = new XMLWriter(); $this->writer->openMemory(); $this->writer->startElementNs(null, $context->nodeName, 'http://schema.phpunit.de/coverage/1.0'); $this->writer->writeAttribute('nr', $line); }
/** * Constructor */ public function __construct() { $this->map = new \XMLWriter(); $this->map->openMemory(); $this->map->startDocument('1.0', 'utf-8'); $this->map->setIndent(true); $this->startSitemap(); }
/** * Construct a new instance of ConnectionParams. * * @param array &$connectionParams Connection parameters for database. */ public function __construct(&$connectionParams) { $this->connectionParams = $connectionParams; $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openMemory(); $this->xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $this->xmlWriter->setIndent(4); }
/** * Start document * * @param mixed $data */ public function startDocument($data) { $this->checkStartDocument($data); $this->isEmpty = true; $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openMemory(); $this->xmlWriter->setIndent($this->formatOutput); $this->xmlWriter->startDocument('1.0', 'UTF-8'); }
public function setUp() { $this->gen = new Misc(); $this->record = new \BeerXML\Record\Misc(); $this->gen->setRecord($this->record); $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openMemory(); $this->gen->setXmlWriter($this->xmlWriter); }
protected function setUp() { $this->generator = new MashProfile(); $this->xml = new \XMLWriter(); $this->xml->openMemory(); $this->generator->setXmlWriter($this->xml); $this->record = new \BeerXML\Record\MashProfile(); $this->generator->setRecord($this->record); parent::setUp(); }
/** * Defined by ReportInterface. * * @see ReportInterface::start() */ public function start() { $this->writer = new XMLWriter(); $this->writer->openMemory(); $this->writer->setIndent(true); $this->writer->setIndentString(' '); $this->writer->startDocument('1.0', 'UTF-8'); $this->writer->startElement('checkstyle'); $this->writer->writeAttribute('version', '5.5'); }
/** * Converts array with export data to XML format. * * @param array $array * * @return string */ public function write(array $array) { $this->xmlWriter->openMemory(); $this->xmlWriter->setIndent($this->formatOutput); $this->xmlWriter->setIndentString(' '); $this->xmlWriter->startDocument('1.0', 'UTF-8'); $this->fromArray($array); $this->xmlWriter->endDocument(); return $this->xmlWriter->outputMemory(); }
public function __toString() { $this->writer->openMemory(); $this->writer->startDocument($this->version, $this->encoding); $this->writer->startElement($this->root); foreach ($this->data as $key => $value) { $this->writeElement($key, $value); } $this->writer->endElement(); $this->writer->endDocument(); return $this->writer->outputMemory(true); }
/** * Convert the request data into XML. * * @since 4.3.0 * @return string */ protected function to_xml() { if (!empty($this->request_xml)) { return $this->request_xml; } $this->xml = new XMLWriter(); // Create XML document in memory $this->xml->openMemory(); // Set XML version & encoding $this->xml->startDocument('1.0', 'UTF-8'); $request_data = $this->get_request_data(); SV_WC_Helper::array_to_xml($this->xml, $this->get_root_element(), $request_data[$this->get_root_element()]); $this->xml->endDocument(); return $this->request_xml = $this->xml->outputMemory(); }
/** * 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; }
protected function _internalRender($name) { $vars = $this->getVars(); $file = $this->getStream(); if ($file === false) { throw new GlobalServiceException("Impossible to create xml file"); } // Start response object fputs($file, '<?xml version="1.0" encoding="UTF-8"?><response>'); // Temp memory $memXml = new XMLWriter(); $memXml->openMemory(); $memXml->setIndent(true); if (isset($vars['count']) && $this->_countKey) { $this->_writeXmlElem($memXml, $this->_countKey, (int) $vars['count']); fputs($file, $memXml->outputMemory()); } // Designed for lists only!!! if (!empty($vars['data']) && count($vars['data']) && $this->_dataKey) { fputs($file, '<' . $this->_dataKey . '>'); foreach ($vars['data'] as $k => $v) { $v = $this->_filterData($v); if ($this->_skipEmptyItems && empty($v)) { continue; } $this->_writeXmlElem($memXml, $k, $v); fputs($file, $memXml->outputMemory()); } fputs($file, '</' . $this->_dataKey . '>'); } // End response object fputs($file, '</response>'); }
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 static function xml_list() { $xw = new XMLWriter(); $xw->openMemory(); $xw->startDocument('1.0', 'UTF-8'); $xw->startElement('Albums'); $xw->setIndent(true); foreach (ORM::factory('Album')->with('genre')->order_by('artist')->order_by('name')->find_all()->as_array() as $album) { $xw->startElement('Album'); $xw->startElement('ID'); $xw->text($album->id); $xw->endElement(); $xw->startElement('Artist'); $xw->text($album->artist); $xw->endElement(); $xw->startElement('Name'); $xw->text($album->name); $xw->endElement(); $xw->startElement('Genre'); $xw->text($album->genre->name); $xw->endElement(); $xw->endElement(); // Album } $xw->endElement(); // Albums $data = $xw->outputMemory(true); $xw->flush(); unset($xw); return $data; }
/** * Write the service document in Atom format. * * @param Object &$dummy Dummy object * * @return string */ public function writeRequest(&$dummy) { $this->_xmlWriter = new \XMLWriter(); $this->_xmlWriter->openMemory(); $this->_xmlWriter->startElementNs(null, ODataConstants::ATOM_PUBLISHING_SERVICE_ELEMENT_NAME, ODataConstants::APP_NAMESPACE); $this->_xmlWriter->writeAttributeNs(ODataConstants::XML_NAMESPACE_PREFIX, ODataConstants::XML_BASE_ATTRIBUTE_NAME, null, $this->_baseUri); $this->_xmlWriter->writeAttributeNs(ODataConstants::XMLNS_NAMESPACE_PREFIX, self::ATOM_NAMESPACE_PREFIX, null, ODataConstants::ATOM_NAMESPACE); $this->_xmlWriter->writeAttributeNs(ODataConstants::XMLNS_NAMESPACE_PREFIX, self::APP_NAMESPACE_PREFIX, null, ODataConstants::APP_NAMESPACE); $this->_xmlWriter->startElement(ODataConstants::ATOM_PUBLISHING_WORKSPACE_ELEMNT_NAME); $this->_xmlWriter->startElementNs(self::ATOM_NAMESPACE_PREFIX, ODataConstants::ATOM_TITLE_ELELMET_NAME, null); $this->_xmlWriter->text(ODataConstants::ATOM_PUBLISHING_WORKSPACE_DEFAULT_VALUE); $this->_xmlWriter->endElement(); foreach ($this->_metadataQueryproviderWrapper->getResourceSets() as $resourceSetWrapper) { //start collection node $this->_xmlWriter->startElement(ODataConstants::ATOM_PUBLISHING_COLLECTION_ELEMENT_NAME); $this->_xmlWriter->writeAttribute(ODataConstants::ATOM_HREF_ATTRIBUTE_NAME, $resourceSetWrapper->getName()); //start title node $this->_xmlWriter->startElementNs(self::ATOM_NAMESPACE_PREFIX, ODataConstants::ATOM_TITLE_ELELMET_NAME, null); $this->_xmlWriter->text($resourceSetWrapper->getName()); //end title node $this->_xmlWriter->endElement(); //end collection node $this->_xmlWriter->endElement(); } //End workspace and service nodes $this->_xmlWriter->endElement(); $this->_xmlWriter->endElement(); $serviceDocumentInAtom = $this->_xmlWriter->outputMemory(true); return $serviceDocumentInAtom; }
/** * Exports the node data of all nodes in the given sub-tree * by writing them to the given XMLWriter. * * @param string $startingPointNodePath path to the root node of the sub-tree to export. The specified node will not be included, only its sub nodes. * @param string $workspaceName * @param \XMLWriter $xmlWriter * @param boolean $tidy * @param boolean $endDocument * @param string $resourceSavePath * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "TYPO3.Neos:Page", "!TYPO3.Neos:Page,TYPO3.Neos:Text") * @return \XMLWriter */ public function export($startingPointNodePath = '/', $workspaceName = 'live', \XMLWriter $xmlWriter = null, $tidy = true, $endDocument = true, $resourceSavePath = null, $nodeTypeFilter = null) { $this->propertyMappingConfiguration = new ImportExportPropertyMappingConfiguration($resourceSavePath); $this->exceptionsDuringExport = array(); $this->exportedNodePaths = array(); if ($startingPointNodePath !== '/') { $startingPointParentPath = substr($startingPointNodePath, 0, strrpos($startingPointNodePath, '/')); $this->exportedNodePaths[$startingPointParentPath] = true; } $this->xmlWriter = $xmlWriter; if ($this->xmlWriter === null) { $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openMemory(); $this->xmlWriter->setIndent($tidy); $this->xmlWriter->startDocument('1.0', 'UTF-8'); } $this->securityContext->withoutAuthorizationChecks(function () use($startingPointNodePath, $workspaceName, $nodeTypeFilter) { $nodeDataList = $this->findNodeDataListToExport($startingPointNodePath, $workspaceName, $nodeTypeFilter); $this->exportNodeDataList($nodeDataList); }); if ($endDocument) { $this->xmlWriter->endDocument(); } $this->handleExceptionsDuringExport(); return $this->xmlWriter; }
/** * Creates the XML * * @return string BeerXML */ public function render() { $this->xmlWriter->openMemory(); $this->xmlWriter->startDocument('1.0', 'UTF-8'); $this->xmlWriter->writeComment('Created with php-beerxml: https://github.com/georgeh/php-beerxml'); list($setTag, $generator) = $this->getTagGeneratorForObject($this->records[0]); /** @var $generator Record */ $generator->setXmlWriter($this->xmlWriter); $this->xmlWriter->startElement($setTag); foreach ($this->records as $record) { $generator->setRecord($record); $generator->build(); } $this->xmlWriter->endElement(); return $this->xmlWriter->outputMemory(true); }
/** * Perform an export according to the given request. * * @param Mage_Core_Controller_Request_Http $request * @param Mage_Core_Controller_Response_Http $response * @throws Exception */ public function process(Mage_Core_Controller_Request_Http $request, Mage_Core_Controller_Response_Http $response) { // In case store is part of URL path use it to choose config. $store = $request->get('store'); if ($store) { $store = Mage::app()->getStore($store); } $apiConfigCharset = Mage::getStoreConfig("api/config/charset", $store); $start_date = strtotime($request->getParam('start_date')); $end_date = strtotime($request->getParam('end_date')); if (!$start_date || !$end_date) { throw new Exception('Start and end dates are required', 400); } $page = (int) $request->getParam('page'); /* @var $orders Mage_Sales_Model_Mysql4_Order_Collection */ $orders = Mage::getResourceModel('sales/order_collection'); // might use 'created_at' attribute instead $orders->addAttributeToFilter('updated_at', array('from' => date('Y-m-d H:i:s', $start_date), 'to' => date('Y-m-d H:i:s', $end_date))); if ($store) { $orders->addAttributeToFilter('store_id', $store->getId()); } if ($page > 0) { $orders->setPage($page, $this->_getExportPageSize()); } $xml = new XMLWriter(); $xml->openMemory(); $xml->startDocument('1.0', $apiConfigCharset); $this->_writeOrders($orders, $xml, $store ? $store->getId() : 0); $xml->endDocument(); $response->clearHeaders()->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset)->setBody($xml->outputMemory(true)); }
public function get() { $posts = Model::factory('Article')->where('status', '1')->order_by_desc('point')->limit(100)->find_many(); $xml = new \XMLWriter(); $xml->openMemory(); $xml->startDocument(); $xml->startElement('urlset'); foreach ($posts as $post) { $xml->startElement('url'); $xml->startElement('loc'); $xml->writeCdata($post->permalink()); $xml->endElement(); $xml->startElement('lastmod'); $xml->writeCdata(date(DATE_ATOM, strtotime($post->modified_at ? $post->modified_at : $post->created_at))); $xml->endElement(); $xml->startElement('changefreq'); $xml->writeCdata('always'); $xml->endElement(); $xml->startElement('priority'); $xml->writeCdata('1.0'); $xml->endElement(); $xml->endElement(); } $xml->endElement(); $this->data = $xml->outputMemory(); }
/** * Create a new \PhpOffice\PhpPowerpoint\Shared\XMLWriter instance * * @param int $pTemporaryStorage Temporary storage location * @param string $pTemporaryStorageDir Temporary storage folder */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = './') { // Create internal XMLWriter $this->xmlWriter = new \XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->xmlWriter->openMemory(); } else { // Create temporary filename $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml'); // Open storage $this->xmlWriter->openUri($this->tempFileName); } // Set default values $this->xmlWriter->setIndent(true); }
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(); }
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; }