當前位置: 首頁>>代碼示例>>PHP>>正文


PHP XmlWriter類代碼示例

本文整理匯總了PHP中XmlWriter的典型用法代碼示例。如果您正苦於以下問題:PHP XmlWriter類的具體用法?PHP XmlWriter怎麽用?PHP XmlWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了XmlWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: render

 protected function render(Response $response)
 {
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $response = clone $response;
     foreach ($response->data as $key => $value) {
         if ($value instanceof ModelSet) {
             $response->data[$key] = $value->toArray();
         }
         if ($value instanceof Form) {
             unset($response->data[$key]);
         }
         if (substr($key, 0, 1) == '_') {
             unset($response->data[$key]);
         }
     }
     if (isset($response->data['application'])) {
         unset($response->data['application']);
     }
     if (isset($response->data['controller'])) {
         unset($response->data['controller']);
     }
     foreach ($response->data as $key => $value) {
         $xml->startElement($key);
         $this->createXML($xml, $value);
         $xml->endElement();
     }
     echo $xml->outputMemory(true);
 }
開發者ID:rday,項目名稱:recess,代碼行數:30,代碼來源:XmlView.class.php

示例2: encode

 public function encode(array $data)
 {
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('api_answer');
     $this->write($xml, $data);
     $xml->endElement();
     return $xml->outputMemory(true);
 }
開發者ID:4otaku,項目名稱:4otaku,代碼行數:10,代碼來源:xml.php

示例3: serializeData

 public function serializeData(DataContainer $data)
 {
     $xml = new \XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('root');
     $this->recursiveSerialize($xml, $data);
     $xml->endElement();
     $xml->endDocument();
     return $xml->outputMemory();
 }
開發者ID:skosm,項目名稱:LaraShop,代碼行數:11,代碼來源:DataSerializerXML.php

示例4: criaXML

function criaXML($response)
{
    $xml = new XmlWriter();
    $xml->openMemory();
    $xml->startDocument('1.0', 'UTF-8');
    $xml->startElement('bvs');
    write($xml, $response);
    $xml->endElement();
    header("Content-Type:text/xml");
    echo $xml->outputMemory(true);
    die;
}
開發者ID:julianirr,項目名稱:TrabalhoSD,代碼行數:12,代碼來源:retornoXML.php

示例5: toXml

 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();
 }
開發者ID:subashemphasize,項目名稱:test_site,代碼行數:14,代碼來源:HtmlTemplate.php

示例6: arrayToXml

 /**
  * Converts a PHP array to XML (via XMLWriter)
  *
  * @param $array PHP Array
  * @return xml-string
  */
 public static function arrayToXml($array)
 {
     // initalize new XML Writer in memory
     $xml = new \XmlWriter();
     $xml->openMemory();
     // with <root> element as top level node
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('root');
     // add the $array data in between
     $this->writeArray($xml, $array);
     // close with </root>
     $xml->endElement();
     // dump memory
     return $xml->outputMemory(true);
 }
開發者ID:Clansuite,項目名稱:Clansuite,代碼行數:21,代碼來源:Conversion.php

示例7: outputXml

 function outputXml($results, $xsltPath)
 {
     /* Setting XML header */
     @header("content-type: text/xml; charset=UTF-8");
     /* Initializing the XML Object */
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->setIndent(true);
     $xml->setIndentString('    ');
     $xml->startDocument('1.0', 'UTF-8');
     if (isset($xsltPath)) {
         $xml->WritePi('xml-stylesheet', 'type="text/xsl" href="' . $xsltPath . '"');
     }
     $xml->startElement('callback');
     $xml->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->writeAttribute('xsi:noNamespaceSchemaLocation', 'schema.xsd');
     /* Function that converts each array element to an XML node */
     function write(XMLWriter $xml, $data)
     {
         foreach ($data as $key => $value) {
             if (is_array($value)) {
                 if (is_numeric($key)) {
                     #The only time a numeric key would be used is if it labels an array with non-uniqe keys
                     write($xml, $value);
                     continue;
                 } else {
                     $xml->startElement($key);
                     write($xml, $value);
                     $xml->endElement();
                     continue;
                 }
             }
             $xml->writeElement($key, $value);
         }
     }
     /* Calls previously declared function, passing our results array as parameter */
     write($xml, $results);
     /* Closing last XML node */
     $xml->endElement();
     /* Printing the XML */
     echo $xml->outputMemory(true);
 }
開發者ID:Abbe98,項目名稱:ODOK,代碼行數:42,代碼來源:Format.php

示例8: buildXML

 /**
  * Build an XML Data Set
  *
  * @param array $data Associative Array containing values to be parsed into an XML Data Set(s)
  * @param string $startElement Root Opening Tag, default data
  * @return string XML String containig values
  * @return mixed Boolean false on failure, string XML result on success
  */
 public function buildXML($data, $startElement = 'xml')
 {
     if (!is_array($data)) {
         $err = 'Invalid variable type supplied, expected array not found on line ' . __LINE__ . " in Class: " . __CLASS__ . " Method: " . __METHOD__;
         trigger_error($err);
         //if($this->_debug) echo $err;
         return false;
         //return false error occurred
     }
     $xml = new XmlWriter();
     $xml->openMemory();
     // $xml->startDocument($this->version, $this->encoding);
     // $xml->startDocument();
     // $xml->startElement($startElement);
     $this->writeEl($xml, $data);
     $xml->endElement();
     //write end element
     //returns the XML results
     return $xml->outputMemory(true);
 }
開發者ID:alvin-ho,項目名稱:wechat-custom-cms,代碼行數:28,代碼來源:ArrayToXML.php

示例9: _writeXmlElem

 /**
  * Write XML data
  *
  * @param XMLWriter $xml   XML object
  * @param string    $key   Data label
  * @param mixed     $value Data
  */
 protected function _writeXmlElem(XmlWriter $xml, $key, $value)
 {
     // Manage objects as array
     if (is_object($value)) {
         $value = get_object_vars($value);
     }
     // Solve tag names issue
     if (is_numeric($key)) {
         $key = 'item' . ucfirst($key);
     }
     // Write XML file
     if (is_array($value)) {
         $xml->startElement($key);
         foreach ($value as $k => $v) {
             $this->_writeXmlElem(&$xml, $k, $v);
         }
         $xml->endElement();
     } else {
         $xml->writeElement($key, $value);
     }
 }
開發者ID:SandeepUmredkar,項目名稱:PortalSMIP,代碼行數:28,代碼來源:Xml.php

示例10: encode

 public static function encode(array $data, $rootNodeName = 'response')
 {
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement($rootNodeName);
     $data = self::arrayify($data);
     function write(XMLWriter $xml, $data)
     {
         foreach ($data as $_key => $value) {
             // check the key isnt a number, (numeric keys invalid in XML)
             if (is_numeric($_key)) {
                 $key = 'element';
             } else {
                 if (!is_string($_key) || empty($_key) || strncmp($_key, '_', 1) === 0) {
                     continue;
                 } else {
                     $key = $_key;
                 }
             }
             $xml->startElement($key);
             // if the key is numeric, add an ID attribute to make tags properly unique
             if (is_numeric($_key)) {
                 $xml->writeAttribute('id', $_key);
             }
             // if the value is an array recurse into it
             if (is_array($value)) {
                 write($xml, $value);
             } else {
                 $xml->text($value);
             }
             $xml->endElement();
         }
     }
     // start the writing process
     write($xml, $data);
     $xml->endElement();
     return $xml->outputMemory();
 }
開發者ID:wave-framework,項目名稱:wave,代碼行數:39,代碼來源:XML.php

示例11: output_xml

 public static function output_xml($data, $version = '0.1', $root = 'root', $parameters = array(), $sItemName = 'item')
 {
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement($root);
     $xml->setIndent(true);
     if (!empty($version)) {
         $xml->writeAttribute('version', $version);
     }
     foreach ($parameters as $paramk => $paramv) {
         $xml->writeAttribute($paramk, $paramv);
     }
     self::writexml($xml, $data, $sItemName);
     $xml->endElement();
     return $xml->outputMemory(true);
 }
開發者ID:catlabinteractive,項目名稱:neuron,代碼行數:17,代碼來源:XML.php

示例12: initialise

 private function initialise()
 {
     /* Setting XML header */
     @header("content-type: application/vnd.google-earth.kml+xml; charset=UTF-8");
     /* Initializing the XML Object */
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->setIndent(true);
     $xml->setIndentString('    ');
     $xml->startDocument('1.0', 'UTF-8');
     return $xml;
 }
開發者ID:Abbe98,項目名稱:ODOK,代碼行數:12,代碼來源:FormatKml.php

示例13: getXml

function getXml($results)
{
    $xml = new XmlWriter();
    $xml->openMemory();
    $xml->setIndent(true);
    // new
    $xml->setIndentString("    ");
    // new
    $xml->startDocument('1.0', 'UTF-8');
    $xml->startElement('root');
    write($xml, $results);
    $xml->endElement();
    $xml->endDocument();
    // new
    $data = $xml->outputMemory(true);
    //$file = file_put_contents(APPPATH . '../uploads/data.xml', $data);
    return $data;
}
開發者ID:heptanol,項目名稱:Test-git,代碼行數:18,代碼來源:test.php

示例14: exportJournal

 function exportJournal()
 {
     $writer = new XmlWriter();
     $writer->openURI($this->outputFolder . "/journal.xml");
     $writer->startDocument('1.0', 'utf-8');
     $writer->startElement('journal');
     $writer->setIndent(true);
     $this->exportJournalConfig($writer);
     $this->exportAnnouncements($writer);
     $this->exportReviewForms($writer);
     $this->exportUsers($writer);
     $this->exportGroups($writer);
     $this->exportSections($writer);
     $this->exportIssues($writer);
     $this->exportArticles($writer);
     $writer->endElement();
     $writer->flush();
     return $this->outputFolder . "/journal.xml";
 }
開發者ID:ulsdevteam,項目名稱:fullJournalTransfer,代碼行數:19,代碼來源:XMLAssembler.inc.php

示例15: render

 public function render($response, $viewModel)
 {
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->setIndent(true);
     $data = $viewModel->toArray();
     $rootNode = $viewModel->getRootNodeName();
     if (!$rootNode) {
         $rootNode = key($data);
         $data = $data[$rootNode];
     }
     if (is_array($data)) {
         $xml->startElement($rootNode);
         $this->write($xml, $data);
         $xml->endElement();
     } else {
         $xml->writeElement($rootNode, utf8_encode($data));
     }
     $response->headers->set('Content-Type', 'application/xml;charset=utf-8');
     $response->setContent($xml->outputMemory(true));
 }
開發者ID:erpk,項目名稱:harserver,代碼行數:22,代碼來源:XML.php


注:本文中的XmlWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。