本文整理汇总了PHP中XmlWriter类的典型用法代码示例。如果您正苦于以下问题:PHP XmlWriter类的具体用法?PHP XmlWriter怎么用?PHP XmlWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: outputXml
/**
* Construct the whole DCAT-AP document given an array of dump info
*
* @param array $data data-blob of i18n and config variables
* @return string: xmldata
*/
function outputXml(array $data)
{
// Initializing the XML Object
$xml = new XmlWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->setIndentString(' ');
// set namespaces
$xml->startDocument('1.0', 'UTF-8');
$xml->startElementNS('rdf', 'RDF', null);
$xml->writeAttributeNS('xmlns', 'rdf', null, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
$xml->writeAttributeNS('xmlns', 'dcterms', null, 'http://purl.org/dc/terms/');
$xml->writeAttributeNS('xmlns', 'dcat', null, 'http://www.w3.org/ns/dcat#');
$xml->writeAttributeNS('xmlns', 'foaf', null, 'http://xmlns.com/foaf/0.1/');
$xml->writeAttributeNS('xmlns', 'adms', null, 'http://www.w3.org/ns/adms#');
$xml->writeAttributeNS('xmlns', 'vcard', null, 'http://www.w3.org/2006/vcard/ns#');
// Calls previously declared functions to construct xml
writePublisher($xml, $data);
writeContactPoint($xml, $data);
$dataset = array();
// Live dataset and distributions
$liveDistribs = writeDistribution($xml, $data, 'ld', null);
if ($data['config']['api-enabled']) {
$liveDistribs = array_merge($liveDistribs, writeDistribution($xml, $data, 'api', null));
}
array_push($dataset, writeDataset($xml, $data, null, $liveDistribs));
// Dump dataset and distributions
if ($data['config']['dumps-enabled']) {
foreach ($data['dumps'] as $key => $value) {
$distIds = writeDistribution($xml, $data, 'dump', $key);
array_push($dataset, writeDataset($xml, $data, $key, $distIds));
}
}
writeCatalog($xml, $data, $dataset);
// Closing last XML node
$xml->endElement();
// Printing the XML
return $xml->outputMemory(true);
}
开发者ID:wikimedia,项目名称:operations-dumps-dcat,代码行数:45,代码来源:DCAT.php
示例17: html
public function html($mysqli_stmt)
{
$xml = new XmlWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->setIndentString("\t");
$xml->startElement('table');
$xml->writeAttribute('class', $this->tbl_class);
$xml->startElement('thead');
$xml->startElement('tr');
//////////////////////////////////
// Column Headers
/////////////////////////////////
$cntcol = count($this->col_classes);
$altcol = 0;
foreach (array_keys($this->cols) as $th) {
$xml->startElement('th');
$xml->writeAttribute('scope', 'col');
if ($this->col_classes[$altcol] != "") {
$xml->writeAttribute('class', $this->col_classes[$altcol]);
}
$altcol = ++$altcol % $cntcol;
if (substr($th, 0, 2) == "__") {
$xml->text('');
} else {
//Sorting
$dir = "A";
if (isset($_GET["sn"]) && $_GET["sn"] == $th && $_GET["sd"] == "A") {
$dir = "D";
}
$xml->startElement('a');
$xml->startAttribute('href');
$xml->writeRaw(quickgrid::get_href(["sn" => $th, "sd" => $dir, "p" => 1]));
$xml->endAttribute();
$xml->text($th);
$xml->endElement();
//a
}
$xml->endElement();
//th
}
$xml->endElement();
//tr
$xml->endElement();
//thead
$xml->startElement('tfoot');
$xml->startElement('tr');
$xml->startElement('td');
$xml->writeAttribute('colspan', count($this->cols));
//////////////////////////////////
// Pager
/////////////////////////////////
$last = ceil($this->row_count / $this->per_page);
$length = 8;
$lbound = $this->cur_page - $length / 2;
$ubound = $this->cur_page + $length / 2;
if ($lbound < 1) {
$lbound = 1;
}
if ($ubound > $last) {
$ubound = $last;
}
if ($this->cur_page != 1) {
$xml->startElement('a');
$xml->startAttribute('href');
$xml->writeRaw(quickgrid::get_href(["p" => $this->cur_page - 1]));
$xml->endAttribute();
$xml->text("<");
$xml->endElement();
//a
}
for ($i = $lbound; $i <= $ubound; $i++) {
if ($i != $this->cur_page) {
$xml->startElement('a');
$xml->startAttribute('href');
$xml->writeRaw(quickgrid::get_href(["p" => $i]));
$xml->endAttribute();
$xml->text("{$i}");
$xml->endElement();
//a
} else {
$xml->startElement('span');
$xml->text("{$i}");
$xml->endElement();
//span
}
}
if ($this->cur_page != $last) {
$xml->startElement('a');
$xml->startAttribute('href');
$xml->writeRaw(quickgrid::get_href(["p" => $this->cur_page + 1]));
$xml->endAttribute();
$xml->text(">");
$xml->endElement();
//a
}
$xml->endElement();
//td
$xml->endElement();
//tr
//.........这里部分代码省略.........
开发者ID:jclifford0251,项目名称:quickphp,代码行数:101,代码来源:quickgrid.php
示例18: buildOpenPayUDocument
/**
* Function builds OpenPayU Xml Document
* @access public
* @param string $data
* @param string $start_element
* @param integer $request
* @param string $xml_version
* @param string $xml_encoding
* @return string $xml
*/
public static function buildOpenPayUDocument($data, $start_element, $request = 1, $xml_version = '1.0', $xml_encoding = 'UTF-8')
{
if (!is_array($data)) {
return false;
}
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument($xml_version, $xml_encoding);
$xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/openpayu.xsd');
$header = $request == 1 ? 'HeaderRequest' : 'HeaderResponse';
$xml->startElement($header);
$xml->writeElement('Algorithm', 'MD5');
$xml->writeElement('SenderName', 'POSID=' . OpenPayUConfiguration::getMerchantPosid() . ';CUSTOM_PLUGIN=PRESTASHOP');
$xml->writeElement('Version', $xml_version);
$xml->endElement();
// domain level - open
$xml->startElement(OpenPayUDomain::getDomain4Message($start_element));
// message level - open
$xml->startElement($start_element);
self::arr2xml($xml, $data);
// message level - close
$xml->endElement();
// domain level - close
$xml->endElement();
// document level - close
$xml->endElement();
return $xml->outputMemory(true);
}
开发者ID:bonekost,项目名称:plugin_prestashop,代码行数:38,代码来源:OpenPayUBase.php
示例19: _getIncidents
/**
* generic function to get incidents by given set of parameters
*/
function _getIncidents($where = '', $limit = '')
{
$items = array();
//will hold the items from the query
$data = array();
//items to parse to json
$json_incidents = array();
//incidents to parse to json
$media_items = array();
//incident media
$json_incident_media = array();
//incident media
$retJsonOrXml = '';
//will hold the json/xml string to return
$replar = array();
//assists in proper xml generation
// Doing this manaully. It was wasting my time trying modularize it.
// Will have to visit this again after a good rest. I mean a good rest.
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->startElement('incidents');
//find incidents
$query = "SELECT i.id AS incidentid,i.incident_title AS incidenttitle," . "i.incident_description AS incidentdescription, i.incident_date AS " . "incidentdate, i.incident_mode AS incidentmode,i.incident_active AS " . "incidentactive, i.incident_verified AS incidentverified, l.id AS " . "locationid,l.location_name AS locationname,l.latitude AS " . "locationlatitude,l.longitude AS locationlongitude FROM incident AS i " . "INNER JOIN location as l on l.id = i.location_id " . "{$where} {$limit}";
$items = $this->db->query($query);
$i = 0;
foreach ($items as $item) {
if ($this->responseType == 'json') {
$json_incident_media = array();
}
//build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->incidentid);
$xml->writeElement('title', $item->incidenttitle);
$xml->writeElement('description', $item->incidentdescription);
$xml->writeElement('date', $item->incidentdate);
$xml->writeElement('mode', $item->incidentmode);
$xml->writeElement('active', $item->incidentactive);
$xml->writeElement('verified', $item->incidentverified);
$xml->startElement('location');
$xml->writeElement('id', $item->locationid);
$xml->writeElement('name', $item->locationname);
$xml->writeElement('latitude', $item->locationlatitude);
$xml->writeElement('longitude', $item->locationlongitude);
$xml->endElement();
$xml->startElement('categories');
//fetch categories
$query = " SELECT c.category_title AS categorytitle, c.id AS cid " . "FROM category AS c INNER JOIN incident_category AS ic ON " . "ic.category_id = c.id WHERE ic.incident_id =" . $item->incidentid . " LIMIT 0 , 20";
$category_items = $this->db->query($query);
foreach ($category_items as $category_item) {
$xml->startElement('category');
$xml->writeElement('id', $category_item->cid);
$xml->writeElement('title', $category_item->categorytitle);
$xml->endElement();
}
$xml->endElement();
//end categories
//fetch media associated with an incident
$query = "SELECT m.id as mediaid, m.media_title AS mediatitle, " . "m.media_type AS mediatype, m.media_link AS medialink, " . "m.media_thumb AS mediathumb FROM media AS m " . "INNER JOIN incident AS i ON i.id = m.incident_id " . "WHERE i.id =" . $item->incidentid . " LIMIT 0 , 20";
$media_items = $this->db->query($query);
if (count($media_items) > 0) {
$xml->startElement('mediaItems');
foreach ($media_items as $media_item) {
if ($this->responseType == 'json') {
$json_incident_media[] = $media_item;
} else {
$xml->startElement('media');
$xml->writeElement('id', $media_item->mediaid);
$xml->writeElement('title', $media_item->mediatitle);
$xml->writeElement('type', $media_item->mediatype);
$xml->writeElement('link', $media_item->medialink);
$xml->writeElement('thumb', $media_item->mediathumb);
$xml->endElement();
}
}
$xml->endElement();
// media
}
$xml->endElement();
// end incident
//needs different treatment depending on the output
if ($this->responseType == 'json') {
$json_incidents[] = array("incident" => $item, "media" => $json_incident_media);
}
}
//create the json array
$data = array("payload" => array("incidents" => $json_incidents), "error" => $this->_getErrorMsg(0));
if ($this->responseType == 'json') {
$retJsonOrXml = $this->_arrayAsJSON($data);
return $retJsonOrXml;
} else {
$xml->endElement();
//end incidents
$xml->endElement();
//.........这里部分代码省略.........
开发者ID:rabble,项目名称:Ushahidi_Web,代码行数:101,代码来源:api.php
示例20: XmlWriter
// -->round(po)
// -->result(ot,ps)
// -->g_h
// -->g_a
// -->p_h
// -->p_a
// -->m_parts
// -->p1(h,a)
// -->p2(h,a)
// -->odds
// -->bo(id)[]
// -->o1
// -->ox
// -->o2
//
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('root');
function write(XMLWriter $xml, $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$xml->startElement($key);
write($xml, $value);
$xml->endElement();
continue;
}
$xml->writeElement($key, $value);
}
}
开发者ID:kaloutsa,项目名称:maksudproject,代码行数:31,代码来源:jsonxml.php
注:本文中的XmlWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论