开发者

Useage of variables in XML file

My XML file look like this:

<?xml versiion="1.0" encoding "utf-8"?>

<graph caption='chart' xAxisName='songs' yAxisName='votes' showNames='0' decimalPrecision='0' formatNumberScale='0'>
 <set name='song name' value='1233' color='AFD8F8' />
 <set name='song name' value='857' color='F6BD0F' />
 <set name='song name' value='671' color='8BBA00' />
 <set name='song name' value='494' color='FF8E46' />
 <set name='song name' value='761' color='008E8E' />
 <set name='song name' value='960' color='D64646' />
 <set name='song name' value='629' color='8E468开发者_开发问答E' />
 <set name='song name' value='622' color='588526' />
 <set name='song name' value='376' color='B3AA00' />
 <set name='song name' value='494' color='008ED6' />
 <set name='song name' value='761' color='9D080D' />
 <set name='song name' value='960' color='A186BE' />
</graph>

Can I use variables in this file in the value='$variable'???

help!!!


Yes, you can use PHP variables if the XML is handled through PHP. In simple terms, just change the extension from .xml to .php, set the content type to xml using header('Content-type: text/xml'). Then you can use the file as it was a normal PHP file:

<?php header('Content-type: text/xml'); echo '<?'; ?>xml version="1.0" encoding "utf-8"<?php echo '?>'; ?>

<graph caption='chart' xAxisName='songs' yAxisName='votes' showNames='0' decimalPrecision='0' formatNumberScale='0'>
<?php foreach($songs as $song): ?>
    <set name='<?php echo $song['name']; ?>' value='<?php echo $song['value']; ?>' color='<?php echo $song['color']; ?>' />
<?php endforeach; ?>
</graph>


Of course you can:

<set name='song name' value='<?php echo $variable;?>' color='588526' />


XML is a text file. You can put whatever text you want into it, but variables don't make sense in this context.

What are you using the XML file for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜