本文整理汇总了PHP中XMLWriter::writeComment方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::writeComment方法的具体用法?PHP XMLWriter::writeComment怎么用?PHP XMLWriter::writeComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::writeComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
public function initialize(Config $config, $directory, $filenameWithDate = false)
{
$this->setFilename($config, $directory, $filenameWithDate);
$this->xml = new \XMLWriter();
$this->xml->openUri($this->filename);
$this->xml->startDocument('1.0', 'utf-8');
$this->xml->setIndent(true);
$this->xml->setIndentString(' ');
$this->xml->writeComment('list of ' . $config->getClassName());
$this->elementName = strtolower($config->getClassNameLastPart());
$this->xml->startElement(strtolower($config->getClassNameLastPart(true)));
}
示例2: handleElement
/**
* Method for parsing of elements
*
* @param string $node - node name
* @param string $item - node content
* @param bool $wrap - should be wrapped in array for singularization
*
* @return void
*
* @since 1.0
*/
protected function handleElement($node, $item, $wrap = true)
{
if ($this->dispatcher->listensTo($node)) {
$this->dispatcher->trigger($node, array($this->writer, $node, $item));
} else {
if ($node === self::COMMENT) {
if (!is_array($item)) {
$item = array($item);
}
foreach ($item as $comment) {
$this->writer->writeComment($comment);
}
} elseif ($node === self::CDATA) {
$this->writer->writeCdata($item);
} else {
if ($wrap === true) {
if ($this->assertElementName($node)) {
if ($this->config->nil_on_null === true && is_null($item)) {
$this->writer->startElement($node);
$this->writer->writeAttribute('xsi:nil', 'true');
$this->writer->writeRaw($item);
$this->writer->endElement();
} else {
$this->writer->writeElement($node, $item);
}
}
} else {
$this->writer->writeRaw($item);
}
}
}
}
示例3: render
/**
* Creates the XML
*
* @return string BeerXML
*/
public function render()
{
$this->xmlWriter->openMemory();
$this->xmlWriter->startDocument('1.0', 'UTF-8');
$this->xmlWriter->writeComment('Created with php-beerxml: https://github.com/georgeh/php-beerxml');
list($setTag, $generator) = $this->getTagGeneratorForObject($this->records[0]);
/** @var $generator Record */
$generator->setXmlWriter($this->xmlWriter);
$this->xmlWriter->startElement($setTag);
foreach ($this->records as $record) {
$generator->setRecord($record);
$generator->build();
}
$this->xmlWriter->endElement();
return $this->xmlWriter->outputMemory(true);
}
示例4: writeReaderImpl
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);
}
}
示例5: generate
/**
* Generates the export
*
* @param integer $categoryId Category Id
* @param boolean $downwards If true, downwards, otherwise upward ordering
* @param string $language Language
*
* @return string
*/
public function generate($categoryId = 0, $downwards = true, $language = '')
{
global $PMF_LANG;
// Initialize categories
$this->category->transform($categoryId);
$faqdata = $this->faq->get(FAQ_QUERY_TYPE_EXPORT_XHTML, $categoryId, $downwards, $language);
$version = $this->_config->get('main.currentVersion');
$comment = sprintf('XHTML output by phpMyFAQ %s | Date: %s', $version, PMF_Date::createIsoDate(date("YmdHis")));
$this->xml->startDocument('1.0', 'utf-8');
$this->xml->writeDtd('html', '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd');
$this->xml->startElement('html');
$this->xml->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
$this->xml->writeAttribute('xml:lang', $language);
$this->xml->writeComment($comment);
$this->xml->startElement('head');
$this->xml->writeElement('title', $this->_config->get('main.titleFAQ'));
$this->xml->startElement('meta');
$this->xml->writeAttribute('http-equiv', 'Content-Type');
$this->xml->writeAttribute('content', 'application/xhtml+xml; charset=utf-8');
$this->xml->endElement();
$this->xml->endElement();
// </head>
$this->xml->startElement('body');
$this->xml->writeAttribute('dir', $PMF_LANG['dir']);
if (count($faqdata)) {
$lastCategory = 0;
foreach ($faqdata as $data) {
if ($data['category_id'] != $lastCategory) {
$this->xml->writeElement('h1', $this->category->getPath($data['category_id'], ' >> '));
}
$this->xml->writeElement('h2', strip_tags($data['topic']));
$this->xml->startElement('p');
$this->xml->writeCdata(html_entity_decode($data['content'], ENT_QUOTES, 'UTF-8'));
$this->xml->endElement();
$this->xml->writeElement('p', $PMF_LANG['msgAuthor'] . ': ' . $data['author_email']);
$this->xml->writeElement('p', $PMF_LANG['msgLastUpdateArticle'] . PMF_Date::createIsoDate($data['lastmodified']));
$lastCategory = $data['category_id'];
}
}
$this->xml->endElement();
// </body>
$this->xml->endElement();
// </html>
header('Content-type: text/html');
return $this->xml->outputMemory();
}
示例6: _dovetail_verify_subscription
function _dovetail_verify_subscription($url, $product_id, $token)
{
$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(true);
$writer->setIndentString(' ');
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('subscription');
if ($token == '') {
$writer->writeAttribute('state', 'inactive');
$writer->writeComment("NO TOKEN PROVIDED");
} else {
// Do the request
$response = _dovetail_verify_entitlement($url, $product_id, $token);
header('Content-type: text/xml');
$check = _dovetail_check_entitlement_response($response);
$failopen = $check['failopen'];
$failmessage = $check['failmessage'];
$state = $check['state'];
if (!$failopen) {
$writer->writeAttribute('state', $state ? 'active' : 'inactive');
} else {
$writer->writeAttribute('state', 'active');
$writer->writeComment("FAILING OPEN: " . $failmessage);
}
$writer->writeComment("Request: " . $response->request);
$status_message = empty($response->status_message) ? null : $response->status_message;
if (isset($response->error) && !is_null($response->error) && $response->error != '' && $response->error != $status_message) {
$writer->writeComment($response->error);
}
$writer->writeComment("Status code: " . $response->code);
$writer->writeComment("Status message: " . $status_message);
}
$writer->endElement();
$writer->endDocument();
header('Content-type: text/xml');
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
echo $writer->outputMemory();
exit;
// Don't do the usual Drupal caching headers etc when completing the request
}
示例7: createRequestXml
/** returns xml for hosted webservice "annul" request */
protected function createRequestXml()
{
$XMLWriter = new \XMLWriter();
$XMLWriter->openMemory();
$XMLWriter->setIndent(true);
$XMLWriter->startDocument("1.0", "UTF-8");
$XMLWriter->writeComment(\Svea\Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
$XMLWriter->startElement($this->method);
$XMLWriter->writeElement("transactionid", $this->transactionId);
$XMLWriter->endElement();
$XMLWriter->endDocument();
return $XMLWriter->flush();
}
示例8: createRequestXml
protected function createRequestXml()
{
$XMLWriter = new \XMLWriter();
$XMLWriter->openMemory();
$XMLWriter->setIndent(true);
$XMLWriter->startDocument("1.0", "UTF-8");
$XMLWriter->writeComment(\Svea\Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
$XMLWriter->startElement($this->method);
$XMLWriter->writeElement("merchantid", $this->config->getMerchantId(\ConfigurationProvider::HOSTED_TYPE, $this->countryCode));
$XMLWriter->endElement();
$XMLWriter->endDocument();
return $XMLWriter->flush();
}
示例9: writeConvertedElement
/**
* Writes out a single property into the XML structure.
*
* @param array $data The data as an array, the given property name is looked up there
* @param string $propertyName The name of the property
* @param string $elementName an optional name to use, defaults to $propertyName
* @return void
*/
protected function writeConvertedElement(array &$data, $propertyName, $elementName = null, $declaredPropertyType = null)
{
if (array_key_exists($propertyName, $data) && $data[$propertyName] !== null) {
$propertyValue = $data[$propertyName];
$this->xmlWriter->startElement($elementName ?: $propertyName);
if (!empty($propertyValue)) {
switch ($declaredPropertyType) {
case null:
case 'reference':
case 'references':
break;
default:
$propertyValue = $this->propertyMapper->convert($propertyValue, $declaredPropertyType);
break;
}
}
$this->xmlWriter->writeAttribute('__type', gettype($propertyValue));
try {
if (is_object($propertyValue) && !$propertyValue instanceof \DateTime) {
$objectIdentifier = $this->persistenceManager->getIdentifierByObject($propertyValue);
if ($objectIdentifier !== null) {
$this->xmlWriter->writeAttribute('__identifier', $objectIdentifier);
}
if ($propertyValue instanceof \Doctrine\ORM\Proxy\Proxy) {
$className = get_parent_class($propertyValue);
} else {
$className = get_class($propertyValue);
}
$this->xmlWriter->writeAttribute('__classname', $className);
$this->xmlWriter->writeAttribute('__encoding', 'json');
$converted = json_encode($this->propertyMapper->convert($propertyValue, 'array', $this->propertyMappingConfiguration));
$this->xmlWriter->text($converted);
} elseif (is_array($propertyValue)) {
foreach ($propertyValue as $key => $element) {
$this->writeConvertedElement($propertyValue, $key, 'entry' . $key);
}
} else {
if ($propertyValue instanceof \DateTime) {
$this->xmlWriter->writeAttribute('__classname', 'DateTime');
}
$this->xmlWriter->text($this->propertyMapper->convert($propertyValue, 'string', $this->propertyMappingConfiguration));
}
} catch (\Exception $exception) {
$this->xmlWriter->writeComment(sprintf('Could not convert property "%s" to string.', $propertyName));
$this->xmlWriter->writeComment($exception->getMessage());
$this->systemLogger->logException($exception);
$this->exceptionsDuringExport[] = $exception;
}
$this->xmlWriter->endElement();
}
}
示例10: generate
/**
* Generates the export
*
* @param integer $categoryId Category Id
* @param boolean $downwards If true, downwards, otherwise upward ordering
* @param string $language Language
*
* @return string
*/
public function generate($categoryId = 0, $downwards = true, $language = '')
{
// Initialize categories
$this->category->transform($categoryId);
$faqdata = $this->faq->get(FAQ_QUERY_TYPE_EXPORT_XML, $categoryId, $downwards, $language);
$version = $this->_config->get('main.currentVersion');
$comment = sprintf('XML output by phpMyFAQ %s | Date: %s', $version, PMF_Date::createIsoDate(date("YmdHis")));
$this->xml->startDocument('1.0', 'utf-8', 'yes');
$this->xml->writeComment($comment);
$this->xml->startElement('phpmyfaq');
if (count($faqdata)) {
foreach ($faqdata as $data) {
// Build the <article/> node
$this->xml->startElement('article');
$this->xml->writeAttribute('id', $data['id']);
$this->xml->writeElement('language', $data['lang']);
$this->xml->writeElement('category', $this->category->getPath($data['category_id'], ' >> '));
if (!empty($data['keywords'])) {
$this->xml->writeElement('keywords', $data['keywords']);
} else {
$this->xml->writeElement('keywords');
}
$this->xml->writeElement('question', strip_tags($data['topic']));
$this->xml->writeElement('answer', PMF_String::htmlspecialchars($data['content']));
if (!empty($data['author_name'])) {
$this->xml->writeElement('author', $data['author_name']);
} else {
$this->xml->writeElement('author');
}
$this->xml->writeElement('data', PMF_Date::createIsoDate($data['lastmodified']));
$this->xml->endElement();
}
}
$this->xml->endElement();
header('Content-type: text/xml');
return $this->xml->outputMemory();
}
示例11: createRequestXml
protected function createRequestXml()
{
$XMLWriter = new \XMLWriter();
$XMLWriter->openMemory();
$XMLWriter->setIndent(true);
$XMLWriter->startDocument("1.0", "UTF-8");
$XMLWriter->writeComment(\Svea\Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
$XMLWriter->startElement($this->method);
$XMLWriter->writeElement("amount", $this->amount);
$XMLWriter->writeElement("customerrefno", $this->customerRefNo);
$XMLWriter->writeElement("subscriptionid", $this->subscriptionId);
if (isset($this->currency)) {
$XMLWriter->writeElement("currency", $this->currency);
}
$XMLWriter->endElement();
$XMLWriter->endDocument();
return $XMLWriter->flush();
}
示例12: instruction
<?php
/* $Id$ */
/*
Libxml 2.6.24 and up adds a new line after a processing instruction (PI)
*/
$xw = new XMLWriter();
$xw->openMemory();
$xw->setIndent(TRUE);
$xw->startDocument("1.0", "UTF-8");
$xw->startElement('root');
$xw->writeAttribute('id', 'elem1');
$xw->startElement('elem1');
$xw->writeAttribute('attr1', 'first');
$xw->writeComment('start PI');
$xw->startElement('pi');
$xw->writePi('php', 'echo "hello world"; ');
$xw->endElement();
$xw->startElement('cdata');
$xw->startCdata();
$xw->text('<>&"');
$xw->endCdata();
$xw->endElement();
$xw->endElement();
$xw->endElement();
$xw->endDocument();
// Force to write and empty the buffer
$output = $xw->flush(true);
print $output;
示例13: renderXML
/**
* builds the XML out of the provided data
*
* @return string the built xml
*/
public function renderXML()
{
$w = new XMLWriter();
$w->openMemory();
// only indent when NICE_XML is true
$w->setIndent(self::NICE_XML);
// use tabs as indents
$w->setIndentString("\t");
$w->startDocument("1.0", CHARSET);
$w->startElement('section');
$w->writeAttribute('name', 'packages');
if (self::SIGNATURE) {
$w->writeComment('Generated by PackageBuilder @ ' . gmdate('r'));
}
try {
if (PAGE_URL == '') {
throw new SystemException('PAGE_URL is empty');
}
foreach ($this->packages as $package) {
// if package has no valid versions just continue
if (self::countValidVersions($package, $this->type) == 0) {
continue;
}
$generalData = self::getPackageData($package);
$w->startElement('package');
$w->writeAttribute('name', $generalData['packageIdentifier']);
$w->startElement('packageinformation');
if ($generalData['packageName'] !== null) {
$w->startElement('packagename');
$w->writeCData($generalData['packageName']);
$w->endElement();
}
if ($generalData['packageDescription'] !== null) {
$w->startElement('packagedescription');
$w->writeCData($generalData['packageDescription']);
$w->endElement();
}
if ($generalData['plugin'] !== null) {
$w->startElement('plugin');
$w->writeCData($generalData['plugin']);
$w->endElement();
}
if ($generalData['standalone'] !== null) {
$w->startElement('standalone');
$w->writeCData($generalData['standalone']);
$w->endElement();
}
// packageinformation
$w->endElement();
$w->startElement('authorinformation');
if ($generalData['author'] !== null) {
$w->startElement('author');
$w->writeCData($generalData['author']);
$w->endElement();
}
if ($generalData['authorURL'] !== null) {
$w->startElement('authorurl');
$w->writeCData($generalData['authorURL']);
$w->endElement();
}
// authorinformation
$w->endElement();
$w->startElement('versions');
// list each version
foreach ($package as $key => $val) {
// get type, dont display if this type is not wanted
if (self::getTypeByVersion($key) != $this->type && $this->type != 'all') {
continue;
}
$data = self::getPackageData($package, $key);
$w->startElement('version');
$w->writeAttribute('name', $key);
if (!empty($data['fromVersions'])) {
$w->startElement('fromversions');
foreach ($data['fromVersions'] as $fromVersion) {
$w->startElement('fromversion');
$w->writeCData($fromVersion);
$w->endElement();
}
// fromversions
$w->endElement();
}
if (!empty($data['requirements'])) {
$w->startElement('requiredpackages');
foreach ($data['requirements'] as $required) {
$w->startElement('requiredpackage');
if (isset($required['minversion'])) {
$w->writeAttribute('minversion', $required['minversion']);
}
$w->writeCData($required['name']);
$w->endElement();
}
// requiredpackages
$w->endElement();
}
//.........这里部分代码省略.........
示例14: exportXmlLog
public function exportXmlLog()
{
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument();
$xml->startElement('invoice-log');
$xml->writeElement('version', '1.0');
// log format version
$xml->startElement('config');
$xml->startElement('item');
$xml->writeAttribute('name', 'plugin.' . $this->paysys_id . '.sample');
$xml->text('VALUE');
$xml->endElement();
$xml->endElement();
$xml->writeComment(sprintf("Dumping invoice#%d, user#%d", $this->invoice_id, $this->user_id));
$xml->startElement('event');
$xml->writeAttribute('time', $this->tm_added);
$this->exportXml($xml, array('element' => 'invoice', 'nested' => array(array('invoiceItem'), array('access', array('element' => 'access')), array('invoicePayment', array('element' => 'invoice-payment')))));
$xml->endElement();
foreach ($this->getDi()->invoiceLogTable->findByInvoiceId($this->pk()) as $log) {
$xml->startElement('event');
$xml->writeAttribute('time', $log->tm);
foreach ($log->getXmlDetails() as $a) {
list($type, $source) = $a;
$xml->writeRaw($source);
}
$xml->endElement();
}
$xml->endElement();
echo $xml->flush();
}
示例15: file_get_contents
<?php
/* $Id$ */
$doc_dest = '001.xml';
$xw = new XMLWriter();
$xw->openUri($doc_dest);
$xw->startDocument('1.0', 'UTF-8');
$xw->startElement("tag1");
$xw->startComment();
$xw->text('comment');
$xw->endComment();
$xw->writeComment("comment #2");
$xw->endDocument();
// Force to write and empty the buffer
$output_bytes = $xw->flush(true);
echo file_get_contents($doc_dest);
unset($xw);
unlink('001.xml');
?>
===DONE===