本文整理汇总了PHP中XMLWriter类的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter类的具体用法?PHP XMLWriter怎么用?PHP XMLWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Voice
public function Voice($MediaId)
{
$w = new \XMLWriter();
$w->openMemory();
$w->writeElement('MediaId', $MediaId);
$this->add('Voice', $w->outputMemory(), true);
}
示例2: setElementFromArray
public function setElementFromArray(XMLWriter $xml, $rootNode, array $config)
{
$config = $this->normalize($config);
if (!empty($config)) {
foreach ($config as $key => $val) {
$numeric = 0;
if (is_numeric($key)) {
$numeric = 1;
$key = $rootNode;
}
if (is_array($val)) {
$isAssoc = $this->isAssoc($val);
if ($isAssoc || $numeric) {
$xml->startElement($key);
}
$this->setElementFromArray($xml, $key, $val);
if ($isAssoc || $numeric) {
$xml->endElement();
}
continue;
}
$xml->writeElement($key, $val);
}
}
}
示例3: _arr2xml
/**
* Takes an array and produces XML based on it.
*
* @param XMLWriter $xmlw XMLWriter object that was previously instanted
* and is used for creating the XML.
* @param array $data Array to be converted to XML.
* @param string $defaultTag Default XML tag to be used if none specified.
*
* @return void
*/
private function _arr2xml(\XMLWriter $xmlw, $data, $defaultTag = null)
{
foreach ($data as $key => $value) {
if ($key === Resources::XTAG_ATTRIBUTES) {
foreach ($value as $attributeName => $attributeValue) {
$xmlw->writeAttribute($attributeName, $attributeValue);
}
} else {
if (is_array($value)) {
if (!is_int($key)) {
if ($key != Resources::EMPTY_STRING) {
$xmlw->startElement($key);
} else {
$xmlw->startElement($defaultTag);
}
}
$this->_arr2xml($xmlw, $value);
if (!is_int($key)) {
$xmlw->endElement();
}
} else {
$xmlw->writeElement($key, $value);
}
}
}
}
示例4: write
public function write(PlatformInterface $platform, \XMLWriter $xmlWriter)
{
$xmlWriter->startElement('video:platform');
$xmlWriter->writeAttribute('relationship', $platform->relationship());
$xmlWriter->text(implode(' ', $platform->types()));
$xmlWriter->endElement();
}
示例5: _internalRender
protected function _internalRender($name)
{
$vars = $this->getVars();
$file = $this->getStream();
if ($file === false) {
throw new GlobalServiceException("Impossible to create xml file");
}
// Start response object
fputs($file, '<?xml version="1.0" encoding="UTF-8"?><response>');
// Temp memory
$memXml = new XMLWriter();
$memXml->openMemory();
$memXml->setIndent(true);
if (isset($vars['count']) && $this->_countKey) {
$this->_writeXmlElem($memXml, $this->_countKey, (int) $vars['count']);
fputs($file, $memXml->outputMemory());
}
// Designed for lists only!!!
if (!empty($vars['data']) && count($vars['data']) && $this->_dataKey) {
fputs($file, '<' . $this->_dataKey . '>');
foreach ($vars['data'] as $k => $v) {
$v = $this->_filterData($v);
if ($this->_skipEmptyItems && empty($v)) {
continue;
}
$this->_writeXmlElem($memXml, $k, $v);
fputs($file, $memXml->outputMemory());
}
fputs($file, '</' . $this->_dataKey . '>');
}
// End response object
fputs($file, '</response>');
}
示例6: write
/**
* @param XMLWriter $xml
* @param $data
*/
public static function write(XMLWriter $xml, $data)
{
foreach ($data as $key => $value) {
if (is_array($value) && isset($value[0])) {
foreach ($value as $itemValue) {
//$xml->writeElement($key, $itemValue);
if (is_array($itemValue)) {
$xml->startElement($key);
self::write($xml, $itemValue);
$xml->endElement();
continue;
}
if (!is_array($itemValue)) {
$xml->writeElement($key, $itemValue . "");
}
}
} else {
if (is_array($value)) {
$xml->startElement($key);
self::write($xml, $value);
$xml->endElement();
continue;
}
}
if (!is_array($value)) {
$xml->writeElement($key, $value . "");
}
}
}
示例7: write
public function write(RestrictionInterface $restriction, \XMLWriter $xmlWriter)
{
$xmlWriter->startElement('video:restriction');
$xmlWriter->writeAttribute('relationship', $restriction->relationship());
$xmlWriter->text(implode(' ', $restriction->countryCodes()));
$xmlWriter->endElement();
}
示例8: writeNamespaceAttributes
private function writeNamespaceAttributes(\XMLWriter $xmlWriter)
{
$xmlWriter->writeAttribute(UrlSetInterface::XML_NAMESPACE_ATTRIBUTE, UrlSetInterface::XML_NAMESPACE_URI);
$xmlWriter->writeAttribute(ImageInterface::XML_NAMESPACE_ATTRIBUTE, ImageInterface::XML_NAMESPACE_URI);
$xmlWriter->writeAttribute(NewsInterface::XML_NAMESPACE_ATTRIBUTE, NewsInterface::XML_NAMESPACE_URI);
$xmlWriter->writeAttribute(VideoInterface::XML_NAMESPACE_ATTRIBUTE, VideoInterface::XML_NAMESPACE_URI);
}
示例9: getItem
protected function getItem()
{
$xml = new \XMLWriter();
$xml->openMemory();
$xml->setIndent(true);
$item = new Price($xml);
return $item;
}
示例10: writeXml
/**
* Write XML to output
*
* @param \XMLWriter $xml
* @param string $nodeName
*
* @return CurrencyAmount
*/
public function writeXml(\XMLWriter $xml, $nodeName)
{
$xml->startElement($nodeName);
$xml->writeAttribute('currency', $this->get('baseCurrencyCode'));
$xml->text($this->get('value'));
$xml->endElement();
return $this;
}
示例11: generateXML
private function generateXML(XmlEntityInterface $xmlEntity)
{
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(false);
$xmlEntity->toXML($xmlWriter);
return $xmlWriter->outputMemory(true);
}
示例12: writeXML
public function writeXML(\XMLWriter $xmlWriter)
{
if ($this->mailAttributes != NULL) {
$xmlWriter->startELement(Constants::MESSAGE_ATTRIBUTES);
$this->mailAttributes->writeXML($xmlWriter);
$xmlWriter->endElement();
}
}
示例13: write
public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
{
if ($stringTag) {
$writer->writeElement('string', $this->value);
} else {
$writer->text($this->value);
}
}
示例14: encodeXml
public static function encodeXml($var)
{
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$xmlWriter->startDocument('1.0', 'UTF-8');
self::encodeXmlNode($xmlWriter, 'root', $var);
return $xmlWriter->flush();
}
示例15: 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);
}
}