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); }
public function __construct($documentUri, $version = '1.0', $encoding = 'utf-8') { $this->xmlWriter = new \XMLWriter(); $this->elementWriter = new ElementWriter($this->xmlWriter); $this->xmlWriter->openUri($documentUri); $this->xmlWriter->setIndent(true); $this->xmlWriter->startDocument($version, $encoding); }
/** * 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); }
/** * 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(" "); }
/** * 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'); }
/** * 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(); }
/** * 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'); }
public function initialize(Config $config, $directory, $filenameWithDate = false) { $this->setFilename($config, $directory, $filenameWithDate); $this->xml = new \XMLWriter(); $this->xml->openUri($this->filename); $this->xml->startDocument('1.0', 'utf-8'); $this->xml->setIndent(true); $this->xml->setIndentString(' '); $this->xml->writeComment('list of ' . $config->getClassName()); $this->elementName = strtolower($config->getClassNameLastPart()); $this->xml->startElement(strtolower($config->getClassNameLastPart(true))); }
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); }
protected function _getWriter() { $writer = new XMLWriter(); $writer->openMemory(); if ($this->_format == self::OUTPUT_PRETTY) { $writer->setIndent(TRUE); $writer->startDocument('1.0', 'UTF-8'); } else { $writer->setIndent(FALSE); $writer->startDocument(); } return $writer; }
/** * Return an XML writer that will be used * to produce XML-RPC requests and responses. * * \retval XMLWriter * XML writer to use to produce documents. */ protected function getWriter() { $writer = new \XMLWriter(); $writer->openMemory(); if ($this->indent) { $writer->setIndent(true); $writer->startDocument('1.0', 'UTF-8'); } else { $writer->setIndent(false); $writer->startDocument(); } return $writer; }
protected function _convertRoot() { // Find first <book> element while (!($this->_reader->nodeType == XMLReader::ELEMENT && $this->_reader->name == 'book')) { $this->_reader->read(); } if (!($this->_reader->nodeType == XMLReader::ELEMENT && $this->_reader->name == 'book')) { throw new ErrorException("Unable to find root book element"); } // Find the title attribute $bookTitle = $this->_reader->getAttribute('title'); if (!$bookTitle) { throw new ErrorException("Unable to find book title attribute"); } // Start XML and write root element $this->_writer->startDocument('1.0', 'UTF-8'); $this->_writer->startElement('book'); $this->_writer->writeAttribute('xmlns', 'http://arr.gr/humanhelp/book'); $this->_writer->writeAttribute('timestamp', time()); // Write title $this->_writer->writeElement('title', $bookTitle); // Write default pageFilters $this->_writer->startElement('pageFilters'); $this->_writer->startElement('filter'); $this->_writer->writeAttribute('class', 'HHLib_XhtmlFilter_FixMediaUrls'); $this->_writer->endElement(); $this->_writer->startElement('filter'); $this->_writer->writeAttribute('class', 'HHLib_XhtmlFilter_FixBSSCPopupUrls'); $this->_writer->endElement(); $this->_writer->endElement(); // Start creating the the TOC $this->_writer->startElement('toc'); while ($this->_reader->read()) { if ($this->_reader->nodeType == XMLReader::ELEMENT) { switch ($this->_reader->name) { case 'page': $this->_convertPage(); break; case 'book': $this->_convertBook(); break; } } } $this->_writer->endElement(); // End of <toc> element $this->_writer->endElement(); // End of root <book> element $this->_writer->endDocument(); $this->_writer->flush(); }
/** * 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(); }
/** * @param Definition $definition * @param \XMLWriter $writer */ protected function initialize($writer, Definition $definition) { $writer->setIndent(true); $writer->setIndentString(" "); $writer->startDocument("1.0", "UTF-8"); $writer->startElement($definition->getNodeName() ?: "root"); }
/** * 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; }
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 array $params * @param string $message * @param int $code */ private function showResponse(array $params, $message = '', $code = 0) { header("Content-type: text/xml; charset=utf-8"); $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0', 'UTF-8'); $writer->startElement($params['action'] . 'Response'); $writer->startAttribute('performedDatetime'); $writer->text(date('c')); $writer->endAttribute(); $writer->startAttribute('code'); $writer->text($code); $writer->endAttribute(); $writer->startAttribute('invoiceId'); $writer->text($params['invoiceId']); $writer->endAttribute(); $writer->startAttribute('message'); $writer->text($message); $writer->endAttribute(); $writer->startAttribute('shopId'); $writer->text($params['shopId']); $writer->endAttribute(); $writer->endElement(); $writer->endDocument(); Yii::app()->end(); }
/** * Fetches the site with the given name and exports it into XML. * * @param array<\TYPO3\TYPO3\Domain\Model\Site> $sites * @return void */ public function export(array $sites) { $this->nodeRepository->getContext()->setInvisibleContentShown(TRUE); $this->nodeRepository->getContext()->setInaccessibleContentShown(TRUE); $xmlWriter = new \XMLWriter(); $xmlWriter->openUri('php://output'); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('root'); foreach ($sites as $site) { $xmlWriter->startElement('site'); // site attributes $xmlWriter->writeAttribute('nodeName', $site->getNodeName()); // site properties $xmlWriter->startElement('properties'); $xmlWriter->writeElement('name', $site->getName()); $xmlWriter->writeElement('state', $site->getState()); $xmlWriter->writeElement('siteResourcesPackageKey', $site->getSiteResourcesPackageKey()); $xmlWriter->endElement(); // on to the nodes... $node = $this->nodeRepository->getContext()->getNode('/Sites/' . $site->getNodeName()); foreach ($node->getChildNodes() as $childNode) { $this->exportNode($childNode, $xmlWriter); } $xmlWriter->endElement(); } $xmlWriter->endElement(); $xmlWriter->endDocument(); $xmlWriter->flush(); }
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); }
/** * 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 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 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; }
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(); }
/** * 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->startDocument('1.0', 'UTF-8'); $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(); $this->_xmlWriter->endDocument(); $serviceDocumentInAtom = $this->_xmlWriter->outputMemory(true); return $serviceDocumentInAtom; }
/** * 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); }
/** * @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 __construct() { $this->openMemory(); parent::startDocument('1.0', 'UTF-8'); $this->startElement('ocs'); $this->error = false; }
public function addPerfil($nome, $dataNascimento, $idade, $codUsuario) { # Instancia do objeto XMLWriter $xml = new XMLWriter(); # Cria memoria para armazenar a saida $xml->openMemory(); # Inicia o cabeçalho do documento XML $xml->startDocument('1.0', 'iso-8859-1'); # Adiciona/Inicia um Elemento / Nó Pai <item> $xml->startElement("perfil"); # Adiciona um Nó Filho <quantidade> e valor 8 $xml->writeElement("nome", $nome); $xml->writeElement("datanascimento", $dataNascimento); $xml->writeElement("idade", $idade); $xml->writeElement("codusuario", $codUsuario); # Finaliza o Nó Pai / Elemento <Item> $xml->endElement(); # Configura a saida do conteúdo para o formato XML header('Content-type: text/xml'); # Imprime os dados armazenados print $xml->outputMemory(true); # Salvando o arquivo em disco # retorna erro se o header foi definido # retorna erro se outputMemory já foi chamado $file = fopen("cod" . $codUsuario . ".xml", "w+"); fwrite($file, $xml->outputMemory(true)); fclose($file); }
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; }