本文整理汇总了PHP中XMLWriter::writeElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::writeElement方法的具体用法?PHP XMLWriter::writeElement怎么用?PHP XMLWriter::writeElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::writeElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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();
}
}
示例3: addPerfil
public function addPerfil($nome, $dataNascimento, $idade, $codUsuario)
{
# Instancia do objeto XMLWriter
$xml = new XMLWriter();
# Cria memoria para armazenar a saida
$xml->openMemory();
# Inicia o cabeçalho do documento XML
$xml->startDocument('1.0', 'iso-8859-1');
# Adiciona/Inicia um Elemento / Nó Pai <item>
$xml->startElement("perfil");
# Adiciona um Nó Filho <quantidade> e valor 8
$xml->writeElement("nome", $nome);
$xml->writeElement("datanascimento", $dataNascimento);
$xml->writeElement("idade", $idade);
$xml->writeElement("codusuario", $codUsuario);
# Finaliza o Nó Pai / Elemento <Item>
$xml->endElement();
# Configura a saida do conteúdo para o formato XML
header('Content-type: text/xml');
# Imprime os dados armazenados
print $xml->outputMemory(true);
# Salvando o arquivo em disco
# retorna erro se o header foi definido
# retorna erro se outputMemory já foi chamado
$file = fopen("cod" . $codUsuario . ".xml", "w+");
fwrite($file, $xml->outputMemory(true));
fclose($file);
}
示例4: 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;
}
示例5: writeXML
public function writeXML(\XMLWriter $xmlWriter)
{
if ($this->maximumMessageSize != NULL) {
$xmlWriter->writeElement(Constants::MAXIMUM_MESSAGE_SIZE, $this->maximumMessageSize);
}
if ($this->messageRetentionPeriod != NULL) {
$xmlWriter->writeElement(Constants::MESSAGE_RETENTION_PERIOD, $this->messageRetentionPeriod);
}
}
示例6: writeXml
/**
* Write XML output
*
* @param \XMLWriter $xml
* @param string $nodeName
*/
public function writeXml(\XMLWriter $xml, $nodeName)
{
$xml->startElement($nodeName);
if ($conditionType = $this->get('ConditionType')) {
$xml->writeElement('ConditionType', $conditionType);
}
if ($conditionNote = $this->get('ConditionNote')) {
$xml->writeElement('ConditionNote', $conditionNote);
}
$xml->endElement();
}
示例7: writeXml
/**
* Write XML output
*
* @param \XMLWriter $xml
* @param string $nodeName
*/
public function writeXml(\XMLWriter $xml, $nodeName)
{
$xml->startElement($nodeName);
if ($type = $this->get('type')) {
$xml->writeElement('Type', $type);
}
if ($value = $this->get('value')) {
$xml->writeElement('Value', $value);
}
$xml->endElement();
}
示例8: writeImagePathElement
/**
*
*/
private function writeImagePathElement()
{
if (isset($this->ticket['issueType']) && $this->ticket['issueType'] == 'Epic' || $this->ticket['issueType'] == 'Bug') {
$this->buffer->writeElement('imagePath', config('printer.imagePath')[$this->ticket['issueType']]);
} else {
// check for mother ship conditions
if (isset($this->ticket['hasSubTasks']) && isset($this->ticket['issueType']) && $this->ticket['hasSubTasks'] == 1 && $this->ticket['issueType'] == 'Story') {
$this->buffer->writeElement('imagePath', config('printer.imagePath')['MotherShip']);
}
}
}
示例9: writeXml
/**
* Write XML output
*
* @param \XMLWriter $xml
* @param string $nodeName
*/
public function writeXml(\XMLWriter $xml, $nodeName)
{
$xml->startElement($nodeName);
if ($sku = $this->get('sku')) {
$xml->writeElement('SKU', $sku);
}
if ($type = $this->get('type')) {
$xml->writeElement('Type', $type);
}
$xml->endElement();
}
示例10: addEntry
/**
* @param string $url
* @param float $priority
* @param string $changefreq
* @param \DateTime $lastmod
*/
public function addEntry($url, $priority = 1.0, $changefreq = 'yearly', \DateTime $lastmod = null)
{
$this->map->startElement('url');
$this->map->writeElement('loc', $url);
$this->map->writeElement('priority', $priority);
$this->map->writeElement('changefreq', $changefreq);
if (false === is_null($lastmod)) {
$this->map->writeElement('lastmod', $lastmod->format('Y-m-d'));
}
$this->map->endElement();
}
示例11: writeXML
public function writeXML(\XMLWriter $xmlWriter)
{
if ($this->endpoint != NULL) {
$xmlWriter->writeElement(Constants::ENDPOINT, $this->endpoint);
}
if ($this->strategy != NULL) {
$xmlWriter->writeElement(Constants::STRATEGY, $this->strategy);
}
if ($this->contentFormat != NULL) {
$xmlWriter->writeElement(Constants::CONTENT_FORMAT, $this->contentFormat);
}
}
示例12: 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);
}
示例13: genAPICredentials
public function genAPICredentials($paylaod)
{
$writer = new XMLWriter();
$writer->openMemory();
#$writer->setIndent(TRUE);
$writer->startElement("APICredentials");
$writer->writeElement("Username", $this->username);
$writer->writeElement("TargetGateway", $this->target_gateway);
$writer->writeElement("PayloadSignature", $this->payloadSignature($paylaod));
$writer->endElement();
return $writer->outputMemory();
}
示例14: writeMessagePropertiesForSendXML
public function writeMessagePropertiesForSendXML(\XMLWriter $xmlWriter)
{
if ($this->messageBody != NULL) {
$xmlWriter->writeElement(Constants::MESSAGE_BODY, base64_encode($this->messageBody));
}
if ($this->delaySeconds != NULL) {
$xmlWriter->writeElement(Constants::DELAY_SECONDS, $this->delaySeconds);
}
if ($this->priority != NULL) {
$xmlWriter->writeElement(Constants::PRIORITY, $this->priority);
}
}
示例15: build
/**
* Construct the record in XMLWriter
*
* @return null
*/
public function build()
{
$this->xmlWriter->startElement($this->tagName);
// Simple required elements
foreach ($this->simpleValues as $tag => $method) {
$this->xmlWriter->writeElement($tag, $this->record->{$method}());
}
foreach ($this->optionalSimpleValues as $tag => $method) {
$value = $this->record->{$method}();
if (!empty($value)) {
$this->xmlWriter->writeElement($tag, $value);
}
}
foreach ($this->complexValues as $generatorClass => $method) {
$value = $this->record->{$method}();
if ($value) {
/** @var Record $generator */
$generator = new $generatorClass();
$generator->setXmlWriter($this->xmlWriter);
$generator->setRecord($value);
$generator->build();
}
}
foreach ($this->complexValueSets as $tag => $complex) {
$this->xmlWriter->startElement($tag);
$method = $complex['values'];
// getter method, should return an array
$generatorClass = $complex['generator'];
// Should be a subclass of BeerXML\Generator\Record
$values = $this->record->{$method}();
$generator = new $generatorClass();
$generator->setXmlWriter($this->xmlWriter);
foreach ($values as $record) {
$generator->setRecord($record);
$generator->build();
}
$this->xmlWriter->endElement();
}
// If the given record implements the interface for the display fields, write those too
if ($this->record instanceof $this->displayInterface) {
foreach ($this->displayValues as $tag => $method) {
$value = $this->record->{$method}();
if (!empty($value)) {
$this->xmlWriter->writeElement($tag, $value);
}
}
}
// Call the parser to allow it to add any other weird fields
$this->additionalFields();
$this->xmlWriter->endElement();
}