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);
     }
 }
 /**
  * @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();
 }
Exemple #3
0
 /**
  * Write discounts info to order
  * @param array $discount
  * @param XMLWriter $xml
  */
 public function writeDiscountsInfo(array $discounts, XMLWriter $xml)
 {
     foreach ($discounts as $rule => $total) {
         $salesRule = Mage::getModel('salesrule/rule')->load($rule);
         if (!$salesRule->getId()) {
             continue;
         }
         $xml->startElement('Item');
         $xml->startElement('SKU');
         $xml->writeCdata($salesRule->getCouponCode() ? $salesRule->getCouponCode() : 'AUTOMATIC_DISCOUNT');
         $xml->endElement();
         $xml->startElement('Name');
         $xml->writeCdata($salesRule->getName());
         $xml->endElement();
         $xml->startElement('Adjustment');
         $xml->writeCdata('true');
         $xml->endElement();
         $xml->startElement('Quantity');
         $xml->text(1);
         $xml->endElement();
         $xml->startElement('UnitPrice');
         $xml->text(-$total);
         $xml->endElement();
         $xml->endElement();
     }
 }
Exemple #4
0
 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 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;
 }
 /**
  * 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 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);
 }
Exemple #8
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();
 }
 public function write(RestrictionInterface $restriction, \XMLWriter $xmlWriter)
 {
     $xmlWriter->startElement('video:restriction');
     $xmlWriter->writeAttribute('relationship', $restriction->relationship());
     $xmlWriter->text(implode(' ', $restriction->countryCodes()));
     $xmlWriter->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();
     }
 }
Exemple #11
0
 public function write(PlatformInterface $platform, \XMLWriter $xmlWriter)
 {
     $xmlWriter->startElement('video:platform');
     $xmlWriter->writeAttribute('relationship', $platform->relationship());
     $xmlWriter->text(implode(' ', $platform->types()));
     $xmlWriter->endElement();
 }
 /**
  * Function to create element with one attribute and value. 
  *  
  * @param string $node           Element name
  * @param string $attribute      Attribute name
  * @param string $attributeValue Attribute value
  * @param string $nodeValue      Element value
  *  
  * @return nothing
  */
 public function writeNodeAttributeValue($node, $attribute, $attributeValue, $nodeValue)
 {
     $this->xmlWriter->startElement($node);
     $this->xmlWriter->writeAttribute($attribute, $attributeValue);
     $this->xmlWriter->text($nodeValue);
     $this->xmlWriter->endElement();
 }
Exemple #13
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']);
     $out->writeAttribute('errors', $report['errors']);
     $out->writeAttribute('warnings', $report['warnings']);
     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['type']);
                 $out->writeAttribute('line', $line);
                 $out->writeAttribute('column', $column);
                 $out->writeAttribute('source', $error['source']);
                 $out->writeAttribute('severity', $error['severity']);
                 $out->text($error['message']);
                 $out->endElement();
             }
         }
     }
     //end foreach
     $out->endElement();
     echo $out->flush();
     return true;
 }
 /**
  * Write keys in $data prefixed with @ as XML attributes, if $data is an array.
  * When an @ prefixed key is found, a '%' key is expected to indicate the element itself,
  * and '#' prefixed key indicates CDATA content
  *
  * @param object $xml XMLWriter Object
  * @param array $data with attributes filtered out
  */
 protected function writeAttr(XMLWriter $xml, $data)
 {
     if (is_array($data)) {
         $nonAttributes = array();
         foreach ($data as $key => $val) {
             //handle an attribute with elements
             if ($key[0] == '@') {
                 $xml->writeAttribute(substr($key, 1), $val);
             } else {
                 if ($key[0] == '%') {
                     if (is_array($val)) {
                         $nonAttributes = $val;
                     } else {
                         $xml->text($val);
                     }
                 } elseif ($key[0] == '#') {
                     if (is_array($val)) {
                         $nonAttributes = $val;
                     } else {
                         $xml->startElement(substr($key, 1));
                         $xml->writeCData($val);
                         $xml->endElement();
                     }
                 } else {
                     $nonAttributes[$key] = $val;
                 }
             }
         }
         return $nonAttributes;
     } else {
         return $data;
     }
 }
Exemple #15
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 #16
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();
 }
 /**
  * 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;
 }
 /**
  * Write XML to output
  * 
  * @param \XMLWriter $xml
  * @param string $nodeName
  * 
  * @return CurrencyAmount 
  */
 public function writeXml(\XMLWriter $xml, $nodeName)
 {
     $xml->startElement($nodeName);
     $xml->writeAttribute('currency', $this->get('baseCurrencyCode'));
     $xml->text($this->get('value'));
     $xml->endElement();
     return $this;
 }
Exemple #19
0
 public function text($content)
 {
     if (strpos($content, "\n") !== false) {
         $is = str_repeat($this->indstr, $this->level);
         $content = "\n{$is}" . str_replace("\n", "\n{$is}", $content) . "\n";
     }
     return parent::text($content);
 }
Exemple #20
0
 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
 {
     if ($stringTag) {
         $writer->writeElement('string', $this->value);
     } else {
         $writer->text($this->value);
     }
 }
 protected function dumpElement($key, $value)
 {
     $this->xml->startElement(strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $key)));
     if (is_array($value)) {
         foreach ($value as $subKey => $subValue) {
             $this->dumpElement($subKey, $subValue);
         }
     } else {
         //need CDATA
         if (preg_match('/[<>&]/', $value)) {
             $this->xml->writeCdata($value);
         } else {
             $this->xml->text($value);
         }
     }
     $this->xml->endElement();
 }
Exemple #22
0
 public function getOpenSearch()
 {
     global $config;
     $xml = new XMLWriter();
     $xml->openMemory();
     $xml->setIndent(true);
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement("OpenSearchDescription");
     $xml->writeAttribute("xmlns", "http://a9.com/-/spec/opensearch/1.1/");
     $xml->startElement("ShortName");
     $xml->text("My catalog");
     $xml->endElement();
     $xml->startElement("Description");
     $xml->text("Search for ebooks");
     $xml->endElement();
     $xml->startElement("InputEncoding");
     $xml->text("UTF-8");
     $xml->endElement();
     $xml->startElement("OutputEncoding");
     $xml->text("UTF-8");
     $xml->endElement();
     $xml->startElement("Image");
     $xml->writeAttribute("type", "image/x-icon");
     $xml->writeAttribute("width", "16");
     $xml->writeAttribute("height", "16");
     $xml->text($config['cops_icon']);
     $xml->endElement();
     $xml->startElement("Url");
     $xml->writeAttribute("type", 'application/atom+xml');
     $urlparam = "?query={searchTerms}";
     if (!is_null(GetUrlParam(DB))) {
         $urlparam = addURLParameter($urlparam, DB, GetUrlParam(DB));
     }
     $urlparam = str_replace("%7B", "{", $urlparam);
     $urlparam = str_replace("%7D", "}", $urlparam);
     $xml->writeAttribute("template", $config['cops_full_url'] . 'feed.php' . $urlparam);
     $xml->endElement();
     $xml->startElement("Query");
     $xml->writeAttribute("role", "example");
     $xml->writeAttribute("searchTerms", "robot");
     $xml->endElement();
     $xml->endElement();
     $xml->endDocument();
     return $xml->outputMemory(true);
 }
 /**
  * Write XML output
  * 
  * @param \XMLWriter $xml
  * @param string $nodeName 
  */
 public function writeXml(\XMLWriter $xml, $nodeName)
 {
     $xml->startElement($nodeName);
     if ($unit = $this->get('unitOfMeasure')) {
         $xml->writeAttribute('unitOfMeasure', $unit);
     }
     $xml->text($this->get('value'));
     $xml->endElement();
 }
Exemple #24
0
 private function writeLicence(\XMLWriter $xmlWriter, $licence = null)
 {
     if ($licence === null) {
         return;
     }
     $xmlWriter->startElement('image:licence');
     $xmlWriter->text($licence);
     $xmlWriter->endElement();
 }
Exemple #25
0
 public function write(UploaderInterface $uploader, \XMLWriter $xmlWriter)
 {
     $xmlWriter->startElement('video:uploader');
     if ($uploader->info() !== null) {
         $xmlWriter->writeAttribute('info', $uploader->info());
     }
     $xmlWriter->text($uploader->name());
     $xmlWriter->endElement();
 }
 public function write(GalleryLocationInterface $galleryLocation, \XMLWriter $xmlWriter)
 {
     $xmlWriter->startElement('video:gallery_loc');
     if ($galleryLocation->title()) {
         $xmlWriter->writeAttribute('title', $galleryLocation->title());
     }
     $xmlWriter->text($galleryLocation->location());
     $xmlWriter->endElement();
 }
Exemple #27
0
 private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null)
 {
     if ($lastModified === null) {
         return;
     }
     $xmlWriter->startElement('lastmod');
     $xmlWriter->text($lastModified->format('c'));
     $xmlWriter->endElement();
 }
Exemple #28
0
 private function writeStockTickers(\XMLWriter $xmlWriter, array $stockTickers)
 {
     if (count($stockTickers) === 0) {
         return;
     }
     $xmlWriter->startElement('news:stock_tickers');
     $xmlWriter->text(implode(', ', $stockTickers));
     $xmlWriter->endElement();
 }
Exemple #29
0
 private function writePriority(\XMLWriter $xmlWriter, $priority = null)
 {
     if ($priority === null) {
         return;
     }
     $xmlWriter->startElement('priority');
     $xmlWriter->text(number_format($priority, 1));
     $xmlWriter->endElement();
 }
 /**
  * Вывод в XMLWriter
  * @codegen true
  * @param XMLWriter $xw
  * @param string $xmlname Имя корневого узла
  * @param string $xmlns Пространство имен
  * @param int $mode
  */
 public function toXmlWriter(\XMLWriter &$xw, $xmlname = self::ROOT, $xmlns = self::NS, $mode = \Adaptor_XML::ELEMENT)
 {
     if ($mode & \Adaptor_XML::STARTELEMENT) {
         $xw->startElementNS(NULL, $xmlname, $xmlns);
     }
     $xw->text($this->_text());
     if ($mode & \Adaptor_XML::ENDELEMENT) {
         $xw->endElement();
     }
 }