本文整理汇总了PHP中XMLWriter::startElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::startElement方法的具体用法?PHP XMLWriter::startElement怎么用?PHP XMLWriter::startElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::startElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateFileReport
/**
* 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']);
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');
$out->writeAttribute('line', $line);
$out->writeAttribute('column', $column);
$out->writeAttribute('severity', $error['type']);
$out->writeAttribute('message', $error['message']);
$out->writeAttribute('source', $error['source']);
$out->endElement();
}
}
}
//end foreach
$out->endElement();
echo $out->flush();
return true;
}
示例2: index
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);
}
示例3: XMLWriter
function impersonate_login($admin_user, $admin_pass, $site, $user)
{
//create a new xmlwriter object
$xml = new XMLWriter();
//using memory for string output
$xml->openMemory();
//set the indentation to true (if false all the xml will be written on one line)
$xml->setIndent(true);
//create the document tag, you can specify the version and encoding here
$xml->startDocument();
//Create an element
$xml->startElement("tsRequest");
$xml->startElement("credentials");
$xml->writeAttribute("name", $admin_user);
$xml->writeAttribute("password", $admin_pass);
$xml->startElement("site");
$xml->writeAttribute("contentUrl", strtoupper($site));
$xml->endElement();
//close contentUrl
$xml->startElement("user");
$xml->writeAttribute("id", $user);
$xml->endElement();
//close user
$xml->endElement();
//close credentials
$xml->endElement();
//close tsRequest
return $data_string = $xml->outputMemory();
}
示例4: Encode
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;
}
示例5: to_html
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();
}
示例6: to_html
public function to_html($parent)
{
if (!$this->get_lang()) {
$this->log("to_html() no lang", 'error');
return null;
}
if (!$this->get_id()) {
$this->log("to_html() no id", 'error');
return null;
}
if (!$parent->get_request()->is_lang_ok($this->get_lang())) {
return null;
}
$w = new XMLWriter();
$w->openMemory();
$w->startElement('div');
$w->writeAttribute('class', 'subtitle');
$w->startElement('a');
$w->writeAttribute('class', 'subtitle_href');
$w->writeAttribute('href', $parent->get_prefix_url() . '/download-' . $this->get_id() . '.html');
$w->startElement('img');
$w->writeAttribute('class', 'subtitle_lang');
$w->writeAttribute('src', $parent->get_prefix_url() . '/images/flags/' . $this->get_lang() . '.gif');
$w->endElement();
$w->endElement();
$w->endElement();
return $w->flush();
}
示例7: writeCommon
private function writeCommon(\XMLWriter $writer, Common $common)
{
if ($common->getAuthor()) {
$writer->startElement('itunes:author');
$writer->writeCdata($common->getAuthor());
$writer->endElement();
}
if ($common->getSummary()) {
$writer->startElement('itunes:summary');
$writer->writeCdata($common->getSummary());
$writer->endElement();
}
if ($common->getBlock()) {
$writer->writeElement('itunes:block', 'Yes');
}
if ($common->getImage()) {
$writer->startElement('itunes:image');
$writer->writeAttribute('href', $common->getImage());
$writer->endElement();
}
$writer->writeElement('itunes:explicit', true === $common->getExplicit() ? 'Yes' : 'No');
if ($common->getSubtitle()) {
$writer->startElement('itunes:subtitle');
$writer->writeCdata($common->getSubtitle());
$writer->endElement();
}
}
示例8: creaXml
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;
}
示例9: to_html
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();
}
示例10: generateTicket
/**
* @param $ticket
*/
private function generateTicket($ticket)
{
$this->ticket = $ticket;
$this->writeSingleElement('key');
$this->writeSingleElement('reporter');
$this->writeSingleElement('issueType');
$this->writeImagePathElement();
$this->writeSingleElement('sprint');
$this->writeSingleElement('summary');
$this->writeSingleElement('devTeam');
$this->writeSingleElement('hasSubTasks');
$this->writeSingleElement('storyPoints');
if (isset($this->ticket['epicData'])) {
$this->buffer->startElement('epic');
$this->buffer->writeElement('key', $this->ticket['epicData']['key']);
$this->buffer->writeElement('summary', $this->ticket['epicData']['summary']);
$this->buffer->endElement();
}
if (isset($this->ticket['parentData'])) {
$this->buffer->startElement('parent');
$this->buffer->writeElement('key', $this->ticket['epicData']['key']);
$this->buffer->writeElement('summary', $this->ticket['epicData']['summary']);
$this->buffer->endElement();
}
}
示例11: getInfoByCode
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);
}
示例12: saveToFile
/**
* @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;
}
示例13: addTest
public function addTest($test)
{
if ($this->finalized) {
throw new PHP_CodeCoverage_RuntimeException('Coverage Report already finalized');
}
$this->writer->startElement('covered');
$this->writer->writeAttribute('by', $test);
$this->writer->endElement();
}
示例14: toXml
public function toXml(XMLWriter $x)
{
$x->writeElement('url', $this->_url);
$x->startElement('params');
foreach ($this->_params as $k => $v) {
$x->startElement('param');
$x->writeAttribute('name', $k);
$x->text($v);
$x->endElement();
}
$x->endElement();
}
示例15: doProcess
protected function doProcess($inputPath, $outputPath)
{
$sitemap = Yaml::parse(file_get_contents($inputPath));
if (!isset($sitemap['locations'])) {
throw new PieCrustException("No locations were defined in the sitemap.");
}
$xml = new \XMLWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument('1.0', 'utf-8');
$xml->startElement('urlset');
$xml->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach ($sitemap['locations'] as $loc) {
$xml->startElement('url');
// loc
$locUrl = $this->pieCrust->getConfig()->getValueUnchecked('site/root') . ltrim($loc['url'], '/');
$xml->writeElement('loc', $locUrl);
// lastmod
$locLastMod = null;
if (isset($loc['lastmod'])) {
$locLastMod = $loc['lastmod'];
} else {
if (isset($loc['lastmod_path'])) {
$fullPath = $this->pieCrust->getRootDir() . ltrim($loc['lastmod_path'], '/\\');
$locLastMod = date('c', filemtime($fullPath));
} else {
$urlInfo = UriParser::parseUri($this->pieCrust, $loc['url']);
if ($urlInfo) {
if (is_file($urlInfo['path'])) {
$locLastMod = date('c', filemtime($urlInfo['path']));
}
}
}
}
if (!$locLastMod) {
throw new PieCrustException("No idea what '" . $loc['url'] . "' is. Please specify a 'lastmod' time, or 'lastmod_path' path.");
}
$xml->writeElement('lastmod', $locLastMod);
// changefreq
if (isset($loc['changefreq'])) {
$xml->writeAttribute('changefreq', $loc['changefreq']);
}
// priority
if (isset($loc['priority'])) {
$xml->writeAttribute('priority', $loc['priority']);
}
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
$markup = $xml->outputMemory(true);
file_put_contents($outputPath, $markup);
}