本文整理汇总了PHP中XmlWriter::endElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlWriter::endElement方法的具体用法?PHP XmlWriter::endElement怎么用?PHP XmlWriter::endElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlWriter
的用法示例。
在下文中一共展示了XmlWriter::endElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: writeChannel
/**
* writeChannel writes a Core\Channel instance feed.
*
* @param Channel $channel
*
* @return mixed Similar to XMLWriter::flush
*
* @see http://php.net/manual/function.xmlwriter-flush.php
*/
public function writeChannel(Channel $channel)
{
$this->xmlWriter->startDocument();
if ($this->flushEarly) {
$this->xmlWriter->flush();
}
$this->xmlWriter->startElement('rss');
foreach ($this->namespaces as $ns => $url) {
$this->xmlWriter->writeAttribute(sprintf('xmlns:%s', $ns), $url);
}
$this->xmlWriter->writeAttribute('version', '2.0');
$this->writeObject($channel);
$this->xmlWriter->endElement();
return $this->xmlWriter->flush();
}
示例3: addEntityInfo
/**
* @param \Product\Entity\Product|Post $entity
*/
public function addEntityInfo($entity)
{
$this->writer->startElement('url');
$this->writer->writeElement('lastmod', date(\Datetime::ATOM, time()));
$this->writer->startElement('image:image');
if ($entity instanceof Post) {
$this->writer->writeElement('image:loc', "http://www.infolightingco.com/images/posts/" . $entity->getThumbnail());
$this->writer->writeElement('loc', "http://www.infolightingco.com/news/" . $entity->getUrl());
} else {
$this->writer->writeElement('image:loc', "http://www.infolightingco.com/images/posts/" . $entity->getThumbnail());
$this->writer->writeElement('loc', "http://www.infolightingco.com/products/view/" . $entity->getProductNumber());
}
$this->writer->endElement();
$this->writer->endElement();
}
示例4: outputSitemap
public function outputSitemap(Kwf_Component_Data $page)
{
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('urlset');
$xml->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach (array_unique($this->_getSitemap($page)) as $url) {
$xml->startElement('url');
$xml->writeElement('loc', $url);
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
header('Content-Type: text/xml; charset=utf-8');
echo $xml->outputMemory(true);
exit;
}
示例5: executeXml
public function executeXml(AgaviRequestDataHolder $request_data)
{
$report = $this->prepareReport($request_data);
$xml = new XmlWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('application');
$xml->writeAttribute('name', $report['application']);
$xml->startElement('status');
$xml->text($report['status']);
$xml->endElement();
$connections = $report['connections'];
$xml->startElement('connections');
foreach ($connections['stats'] as $name => $value) {
$xml->writeAttribute($name, $value);
}
$xml->writeElement('status', $connections['status']);
$xml->startElement('stats');
foreach ($connections['stats'] as $name => $value) {
$xml->writeElement($name, $value);
}
$xml->endElement();
// connections/stats
foreach ($connections['details'] as $name => $value) {
$xml->startElement('connection');
$xml->writeAttribute('name', $name);
if (is_array($value)) {
$this->array2xml($value, $xml);
} else {
$xml->writeCData((string) $value);
}
$xml->endElement();
}
$xml->endElement();
// connections
$xml->endElement();
// application
$xml->endDocument();
return $xml->outputMemory();
}
示例6: toXml
function toXml(XmlWriter $x, $writeEnvelope = true)
{
if ($writeEnvelope) {
$x->startElement('http-request');
}
$x->startElement('method');
$x->text($this->getMethod());
$x->endElement();
$x->startElement('url');
$x->text($this->getUrl());
$x->endElement();
$x->startElement('headers');
foreach ($this->getHeaders() as $k => $v) {
$x->startElement('header');
$x->writeAttribute('name', $k);
$x->text($v);
$x->endElement();
}
$x->endElement();
$x->startElement('params');
foreach ($this->getPostParams() as $k => $v) {
$x->startElement('param');
$x->writeAttribute('name', $k);
$x->text($v);
$x->endElement();
}
$x->endElement();
if (!$this->getPostParams() && $this->getBody()) {
$x->startElement('body');
$x->writeCdata($this->getBody());
$x->endElement();
}
if ($writeEnvelope) {
$x->endElement();
}
}
示例7: array
/**
* 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();
//.........这里部分代码省略.........
示例8: objectSerialize
/**
* Serialize an object with specified root element name.
*
* @param object $targetObject The target object.
* @param string $rootName The name of the root element.
*
* @return string
*/
public static function objectSerialize($targetObject, $rootName)
{
Validate::notNull($targetObject, 'targetObject');
Validate::isString($rootName, 'rootName');
$xmlWriter = new \XmlWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$reflectionClass = new \ReflectionClass($targetObject);
$methodArray = $reflectionClass->getMethods();
$attributes = self::_getInstanceAttributes($targetObject, $methodArray);
$xmlWriter->startElement($rootName);
if (!is_null($attributes)) {
foreach (array_keys($attributes) as $attributeKey) {
$xmlWriter->writeAttribute($attributeKey, $attributes[$attributeKey]);
}
}
foreach ($methodArray as $method) {
if (strpos($method->name, 'get') === 0 && $method->isPublic() && $method->name != 'getAttributes') {
$variableName = substr($method->name, 3);
$variableValue = $method->invoke($targetObject);
if (!empty($variableValue)) {
if (gettype($variableValue) === 'object') {
$xmlWriter->writeRaw(XmlSerializer::objectSerialize($variableValue, $variableName));
} else {
$xmlWriter->writeElement($variableName, $variableValue);
}
}
}
}
$xmlWriter->endElement();
return $xmlWriter->outputMemory(true);
}
示例9: array
/**
* do the search via the API
* @param q - the search string.
*
* @param limit - the value to limit by.
*
* @return the search result.
*/
function _doSearch($q, $limit)
{
/**
* This is mostly borrowed from the search functionality
* see application/controller/search.php
*/
$search_query = "";
$keyword_string = "";
$where_string = "";
$plus = "";
$or = "";
$search_info = "";
$html = "";
$json_searches = array();
// Stop words that we won't search for
// Add words as needed!!
$stop_words = array('the', 'and', 'a', 'to', 'of', 'in', 'i', 'is', 'that', 'it', 'on', 'you', 'this', 'for', 'but', 'with', 'are', 'have', 'be', 'at', 'or', 'as', 'was', 'so', 'if', 'out', 'not');
$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 to 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('searches');
$keywords = explode(' ', $q);
if (is_array($keywords) && !empty($keywords)) {
array_change_key_case($keywords, CASE_LOWER);
$i = 0;
foreach ($keywords as $value) {
if (!in_array($value, $stop_words) && !empty($value)) {
$chunk = mysql_real_escape_string($value);
if ($i > 0) {
$plus = ' + ';
$or = ' OR ';
}
// Give relevancy weighting
// Title weight = 2
// Description weight = 1
$keyword_string = $keyword_string . $plus . "(CASE WHEN incident_title LIKE '%{$chunk}%' THEN 2 ELSE 0 END) + (CASE WHEN incident_description LIKE '%{$chunk}%' THEN 1 ELSE 0 END)";
$where_string = $where_string . $or . "incident_title LIKE '%{$chunk}%' OR incident_description LIKE '%{$chunk}%'";
$i++;
}
}
if (!empty($keyword_string) && !empty($where_string)) {
$search_query = "SELECT *, (" . $keyword_string . ") AS relevance FROM incident WHERE (" . $where_string . ") ORDER BY relevance DESC ";
}
}
if (!empty($search_query)) {
if (!empty($limit) && is_numeric($limit)) {
$l = "LIMIT 0 ," . $limit;
} else {
$l = " LIMIT ," . $this->list_limit;
}
$total_items = ORM::factory('incident')->where($where_string)->count_all();
$s = $search_query . $l;
$query = $this->db->query($s);
$this->total_records = $total_items;
// Results Bar
if ($total_items != 0) {
if ($this->responseType == 'json') {
$json_searches[] = array("total" => $total_items);
} else {
$xml->writeElement('total', $total_items);
}
} else {
$xml->writeElement('total', $total_items);
//create the json array
$data = array("payload" => array("searches" => $json_searches), "error" => $this->_getErrorMsg(0));
if ($this->responseType == 'json') {
$retJsonOrXml = $this->_arrayAsJSON($data);
return $retJsonOrXml;
} else {
$xml->endElement();
//end searches
$xml->endElement();
// end payload
$xml->startElement('error');
$xml->writeElement('code', 0);
$xml->writeElement('message', 'No Error');
$xml->endElement();
//end error
$xml->endElement();
// end response
return $xml->outputMemory(true);
}
}
//.........这里部分代码省略.........
示例10: _serializeAtom
/**
* Serializes the atom into XML representation.
*
* @param array $properties The atom properties.
*
* @return string
*/
private function _serializeAtom($properties)
{
$xmlw = new \XmlWriter();
$xmlw->openMemory();
$xmlw->setIndent(true);
$xmlw->startDocument(strtoupper($this->_xmlVersion), $this->_xmlEncoding, 'yes');
$xmlw->startElementNS(null, 'entry', $this->_atomNamespaceName);
$xmlw->writeAttribute("xmlns:{$this->_dataServicesPrefix}", $this->_dataServicesNamespaceName);
$xmlw->writeAttribute("xmlns:{$this->_dataServicesMetadataPrefix}", $this->_dataServicesMetadataNamespaceName);
$xmlw->writeElement('title');
$xmlw->writeElement('updated', Utilities::isoDate());
$xmlw->startElement('author');
$xmlw->writeElement('name');
$xmlw->endElement();
$xmlw->writeElement('id');
$xmlw->startElement('content');
$xmlw->writeAttribute('type', Resources::XML_CONTENT_TYPE);
$xmlw->startElementNS($this->_dataServicesMetadataPrefix, 'properties', null);
$this->_generateProperties($xmlw, $properties);
$xmlw->endElement();
$xmlw->endElement();
$xmlw->endElement();
return $xmlw->outputMemory(true);
}
示例11: generate
/**
* Generates the XML output and saves it to a file or returns it as a string
*
* @return null|int Returns the number of bytes written to a local file or false on failure
*/
protected function generate()
{
$w = new \XmlWriter();
$w->openMemory();
$w->setIndent(true);
$w->setIndentString(" ");
$w->startDocument('1.0', 'utf-8');
$w->startElement($this->rootname);
$row = $this->getRow();
$keys = array_keys($row);
foreach ($keys as $key) {
$this->isValidName($key);
}
do {
$w->startElement($this->rowname);
foreach ($row as $key => $value) {
if ($this->suppress && in_array($key, $this->suppress)) {
continue;
}
if ($this->hasChildren && in_array($key, $this->hasChildren)) {
$stripped = $this->stripHtml($value);
$w->startElement($key);
foreach ($stripped as $para) {
$w->writeElement('p', $para);
}
$w->endElement();
} else {
$w->writeElement($key, $value);
}
}
$w->endElement();
} while ($row = $this->getRow());
$w->endElement();
$w->endDocument();
$this->xml = $w->outputMemory();
// write to file
if (isset($this->filename) && $this->local) {
$success = file_put_contents($this->filename, $this->xml);
return $success;
} elseif (isset($this->filename) && $this->download) {
$this->outputHeaders();
file_put_contents('php://output', $this->xml);
exit;
}
}
示例12: XmlWriter
<?php
$xml = new XmlWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument();
$xml->startElement('test');
$xml->writeElement('foo', null);
$xml->writeElement('foo2', "");
$xml->writeElement('foo3');
$xml->startElement('bar');
$xml->endElement('bar');
$xml->endElement();
$xml->endElement();
print $xml->flush(true);
print "\n";
$xw = new XMLWriter();
$xw->openMemory();
$xw->setIndent(true);
$xw->startDocument();
$xw->startElementNS('test', 'test', 'urn:x-test:');
$xw->writeElementNS('test', 'foo', null, '');
$xw->writeElementNS(null, 'bar', 'urn:x-test:', '');
$xw->writeElementNS(null, 'bar', 'urn:x-test:', NULL);
$xw->writeElementNS(null, 'bar', 'urn:x-test:');
$xw->writeElementNS(null, 'bar', '', '');
$xw->endElement();
$xw->endDocument();
print $xw->flush(true);
示例13: toXml
function toXml(XmlWriter $x)
{
$x->startElement('url');
$x->startElement('method');
$x->text($this->getMethod());
$x->endElement();
$x->startElement('scheme');
$x->text($this->getScheme());
$x->endElement();
$x->startElement('base_url');
$x->text($this->getBaseUrl(true));
$x->endElement();
$x->startElement('path_info');
$x->text($this->getPathInfo());
$x->endElement();
$x->startElement('host');
$x->text($this->getHttpHost());
$x->endElement();
$x->startElement('remote_addr');
$x->text($this->getClientIp(false));
$x->endElement();
$x->endElement();
$x->startElement('params');
foreach ($this->getRequestOnlyParams() as $k => $v) {
$x->startElement('param');
$x->writeAttribute('name', $k);
if (is_array($v) || is_object($v)) {
$v = json_encode($v);
$x->writeAttribute("serialized", "json");
$x->writeCdata($v);
} else {
$x->text($v);
}
$x->endElement();
}
$x->endElement();
}
示例14: XmlWriter
$msg = '';
$sch = '';
continue;
} else {
$msg = $feed->SMSCONTENT;
$sch = $feed->TIME;
if (!empty($msg) && $sch > $older_sch) {
$older_sch = $sch;
} else {
continue;
}
}
$xml = new XmlWriter();
echo $msg;
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('content');
$xml->writeElement('updTime', gmdate('Y-m-d\\TH:i:s\\Z', strtotime($older_sch)));
$xml->startElement('body');
$xml->writeCData($msg);
$xml->endElement();
$xml->startElement('preview');
$xml->writeCData(stripslashes($msg));
$xml->endElement();
$xml->endElement();
echo 'yes4<br>';
$file = "serieaweekly.xml";
echo $file;
file_put_contents("rss/" . $file, $xml->outputMemory(true));
}
echo '<br>done!';
示例15: generate
/**
* Generates the XML output and saves it to a file or returns it as a string
*
* @return null|int Returns the number of bytes written to a local file or false on failure
*/
protected function generate()
{
$w = new \XmlWriter();
$w->openMemory();
$w->setIndent(true);
$w->setIndentString(" ");
$w->startDocument('1.0', 'utf-8');
$w->startElement($this->rootname);
while ($object = $this->getRow()) {
// Start a new row for each object
$w->startElement($this->rowname);
foreach ($object as $key => $value) {
if ($this->suppress && in_array($key, $this->suppress)) {
continue;
}
$this->isValidName($key);
// Check if the key contains another object
if (is_object($value)) {
// Start parent element containing rows of each object
$w->startElement($key . "s");
// $value is an array of objects
foreach ($value as $obj) {
$w->startElement($key);
foreach ($obj as $field => $val) {
$this->isValidName($key);
$w->writeElement($field, $val);
}
$w->endElement();
}
$w->endElement();
} else {
// Write each object's property->value as <key>value</key>
if ($this->hasChildren && in_array($key, $this->hasChildren)) {
$stripped = $this->stripHtml($value);
$w->startElement($key);
foreach ($stripped as $para) {
$w->writeElement('p', $para);
}
$w->endElement();
} else {
$w->writeElement($key, $value);
}
}
}
$w->endElement();
}
$w->endElement();
$w->endDocument();
$this->xml = $w->outputMemory();
// write to file
if (isset($this->filename) && $this->local) {
$success = file_put_contents($this->filename, $this->xml);
return $success;
} elseif (isset($this->filename) && $this->download) {
$this->outputHeaders();
file_put_contents('php://output', $this->xml);
exit;
}
}