I have this xml that works for Flash Encoder:
<?xml version="1.0" encoding="UTF-8"?>
<flashmedialiveencoder_profile>
<preset>
<name></name>
<description></description>
</preset>
<capture>
<video>
<device></device>
<crossbar_input>1</crossbar_input>
<frame_rate>25.00</frame_rate>
<size>
<width></width>
<height></height>
</size>
</video>
<audio>
<device></device>
<crossbar_input>2</crossbar_input>
<sample_rate></sample_rate>
<channels>1</channels>
<input_volume>60</input_volume>
</audio>
</capture>
<encode>
<video>
<format>H.264</format>
<datarate></datarate>
<outputsize></outputsize>
<advanced>
<profile></profile>
<level></level>
<keyframe_frequency>5 Seconds</keyframe_frequency>
</advanced>
<autoadjust>
<enable>false</enable>
<maxbuffersize>1</maxbuffersize>
<dropframes>
<enable>false</enable>
</dropframes>
<degradequality>
<enable>false</enable>
<minvideobitrate></minvideobitrate>
<preservepfq>false</preservepfq>
</degradequality>
</autoadjust>
</video>
<audio>
<format>MP3</format>
<datarate></datarate>
</audio>
</encode>
<restartinterval>
<days></days>
<hours></hours>
<minutes></minutes>
</restartinterval>
<reconnectinterval>
<attempts></attempts>
<interval></interval>
</reconnectinterval>
<output>
<rtmp>
<url></url>
<backup_url></backup_url>
<stream></stream>
</rtmp>
</output>
<metadata>
<entry>
<key>author</key>
<value></value>
</entry>
<entry>
<key>copyright</key>
<value></value>
</entry>
<entry>
<key>description</key>
<value></value>
</entry>
<entry>
<key>keywords</key>
<value></value>
</entry>
<entry>
<key>rating</key>
<value></value>
</entry>
<entry>
<key>title</key>
<value></value>
</entry>
</metadata>
<preview>
<video>
<input>
<zoom>50%</zoom>
</input>
<output>
<zoom>50%</zoom>
</output>
</video>
<audio></audio>
</preview>
<log>
<level>100</level>
<directory></directory>
</log>
</flashmedialiveencoder_profile>
And I need to update some of the data depending on the type of xml the user requires. So I want to do something like this:
$data = array (
'preset' => array (
'name' => 'Low Bandwidth (150 Kbps) - H.264',
),
'capture' => array (
'audio' => array (
'sample_rate' => 44100
)
),
'encode' => array (
'video' => array (
'datarate' => '300;',
'outputsize' => '480x360;',
'advanced' => array (
'profile' => 'Main',
'level' => 2.1,
)
),
'audio' => array (
'datarate' => 48
)
),
);
I know this tree works, cause I can do it manually, but the problem is that I don't want to do it like that, so if in the future I need to change other think in the xml, I have only to add it to the array configuration.
How can I do it? I can write a recursive function to do it, but I don't really want to do it in that way. Is there any other way to do it? I don't know... may be something like:
$xml->updateFromArray($data);
As I repeat, I can write that function and extend SimpleXMLElement, but if there is any other native php method to do it, it will be better.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…