需要使用PHP编写XML-怎么做? [英] Need to write XML using PHP - how?
本文介绍了需要使用PHP编写XML-怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经有了基本代码.
<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编写此文件的文档.
it's used from fusionwidgets and there's no documentation on how to write this in PHP.
有人可以建议吗?
推荐答案
有完整的示例,其中包含 php.net/XMLWriter生成与您发布的完全相同的XML输出.
There is complete example with php.net/XMLWriter to produce exactly the same XML output like you posted.
<?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编写XML-怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文