У меня есть этот базовый код.
<chart lowerLimit='0' upperLimit='100' caption='Revenue' subcaption='US $ (1,000s)' numberPrefix='$' numberSuffix='K' showValue='1' > <colorRange> <color minValue='0' maxValue='50' color='A6A6A6'/> <color minValue='50' maxValue='75' color='CCCCCC'/> <color minValue='75' maxValue='100' color='E1E1E1'/> </colorRange> <value>78.9</value> <target>80</target> </chart>
он используется из fusionwidgets и нет документации о том, как писать это на PHP.
может кто-нибудь посоветовать?
Существует полный пример с php.net/XMLWriter для получения точно такого же XML-вывода, как вы опубликовали.
<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('chart'); $writer->writeAttribute('lowerLimit', '0'); $writer->writeAttribute('upperLimit', '100'); $writer->writeAttribute('caption', 'Revenue'); $writer->writeAttribute('subcaption', 'US $ (1,000s)'); $writer->writeAttribute('numberPrefix', '$'); $writer->writeAttribute('numberSuffix', 'K'); $writer->writeAttribute('showValue', '1'); $writer->startElement('colorRange'); $writer->startElement('color'); $writer->writeAttribute('minValue', '0'); $writer->writeAttribute('maxValue', '50'); $writer->writeAttribute('color', 'A6A6A6'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '50'); $writer->writeAttribute('maxValue', '75'); $writer->writeAttribute('color', 'CCCCCC'); $writer->endElement(); $writer->startElement('color'); $writer->writeAttribute('minValue', '75'); $writer->writeAttribute('maxValue', '100'); $writer->writeAttribute('color', 'E1E1E1'); $writer->endElement(); $writer->endElement(); $writer->writeElement('value','78.9'); $writer->writeElement('target','78.9'); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
Моим любимым способом записи XML-файлов является XMLWriter – http://php.net/xmlwriter . Это очень мощный и простой в использовании.
<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
-<?php $writer = new XMLWriter(); $writer->openURI('php://output'); $writer->startDocument('1.0','UTF-8'); $writer->setIndent(4); $writer->startElement('items'); $writer->startElement("main"); $writer->writeElement('user_id', 3); $writer->writeElement('msg_count', 11); $writer->endElement(); $writer->startElement("msg"); $writer->writeAttribute('category', 'test'); $writer->endElement(); $writer->endElement(); $writer->endDocument(); $writer->flush(); ?>
И эта часть кода создаст следующий XML:
<?xml version="1.0" encoding="UTF-8"?> <items> <main> <user_id>3</user_id> <msg_count>11</msg_count> </main> <msg category="test"/> </items>
Видеть
Лично я предпочитаю DOM для работы с XML.
Возможно, вы захотите уточнить свой вопрос. Сейчас трудно сказать, в чем проблема.
SimpleXML, встроенный в PHP, является самым простым решением для написания (и анализа) XML. http://php.net/manual/en/book.simplexml.php
С FluidXML вы можете создать свой XML таким образом.
$chart = fluidxml('chart'); $chart->attr('lowerLimit', 0) ->attr('upperLimit', 100) ->attr(...) ->add('colorRange') ->add('value', 78.9) ->add('target', 80) ->query('//colorRange') ->add('color', ['minValue' => 0, 'maxValue' => 50, ...]) ->add('color', ['minValue' => 50, 'maxValue' => 75, ...]) ->add('color', ['minValue' => 75, 'maxValue' => 100, ...]);
Как упоминалось ранее, setIndent устанавливает отступы и должен использоваться следующим образом:
$writer->setIndent(true);
если вы хотите установить размер отступов на другой, чем по умолчанию (2 пробела), вы можете использовать setIndentString:
$writer->setIndentString(" ");