开发者

creating dynamic xml with php

开发者 https://www.devze.com 2022-12-14 22:25 出处:网络
here is my xml code <autoLoad value=\"true\"/> <autoPlay value=\"false\"/> <playContinuously value=\"true\"/>

here is my xml code

    <autoLoad value="true"/>
    <autoPlay value="false"/>
    <playContinuously value="true"/>
    <jumpToNextCategory value="false"/>
    <loop value="false"/>

    <keepAspectRatio value="true"/>

    <volume value="50"/>
    <controlsPadding value="5"/>

    <showPreviewImage value="true"/>
    <showShareBtn value="false"/>
    <showHidePlaylistBtn value="false"/>
    <showFullScreenBtn value="true"/>
    <showMiddlePlayBtn value="true"/>

    <showWatermark value="true"/>
    <watermarkPos value开发者_JAVA百科="BR"/>

    <spaceKeyListener value="true"/>
    <clickListener value="true"/>

    <playlistSize value="0"/>
    <playlistThumbWidth value="70"/>
    <playlistThumbHeight value="50"/>
    <playlistThumbPadding value="10"/>

    <descriptionSize value="0"/>
    <descriptionTextPadding value="10"/>
</options>

<colors>
    <playerBackground value="0x000000"/>
    <preloader background="0x000000" bckAlpha="70" text="0xCCCCCC" circle="0x559BB5"/>
    <middlePlayBtn arrowNormal="0xFFFFFF" bckNormal="0x000000" alphaNormal="60" arrowOver="0xFFFFFF" bckOver="0x000000" alphaOver="80" arrowDown="0xFFFFFF" bckDown="0x000000" alphaDown="100"/>
    <controllerBackground value="0x000000"/>
    <controllerButtons normal="0xCCCCCC" over="0xFFFFFF" down="0xFFFFFF"/>
    <volume border="0x666666" background="0x000000" speaker="0xCCCCCC" bar="0x559BB5"/>
    <volumeScrubBtn brdNormal="0xCCCCCC" bckNormal="0x000000" brdOver="0xFFFFFF" bckOver="0x000000" brdDown="0xFFFFFF" bckDown="0x000000" />
    <progressBar border="0x666666" background="0x000000" elapse="0x559BB5" download="0x999999"/>
    <progressScrubBtn brdNormal="0xCCCCCC" bckNormal="0x000000" brdOver="0xFFFFFF" bckOver="0x000000" brdDown="0xFFFFFF" bckDown="0x000000" />
    <times value="0xCCCCCC"/>
    <share background="0x000000" bckAlpha="40" boxBck="0x000000" boxBckAlpha="70" labels="0xFFFFFF" errorText="0x00FF00" text="0x000000" textBck="0xFFFFFF" textBrd="0x000000" btnsNormal="0xCCCCCC" btnsOver="0xFFFFFF" btnsDown="0xFFFFFF"/>
    <playlist background="0x151515" line="0x202020" thumbBck="0x000000" thumbNormalAlpha="30" thumbOverAlpha="70" thumbSelectedAlpha="100" title="0x559BB5" description="0xCCCCCC"/>
    <category bckNormal="0x101010" titleNormal="0xCCCCCC" bckOver="0x000000" titleOver="0xFFFFFF" bckSelected="0x559BB5" titleSelected="0x000000"/>
    <description background="0x151515" line="0x202020" title="0xFFFFFF" description="0xCCCCCC"/>
    <scrollBar trackBar="0xCCCCCC" scrubBrdNormal="0xCCCCCC" scrubBckNormal="0x000000" scrubBrdOver="0xFFFFFF" scrubBckOver="0x000000" scrubBrdDown="0xFFFFFF" scrubBckDown="0x000000"/>
</colors>

<videos>
    <category title="Animations">
    <video>
    <videoPath value="video.mp4"/>
    <previewImage value="image.jpg"/>
    <aspectRatio value="4:3"/>
    <totalTime value=""/>
    <watermarkPath value="http://mydomain.com"/>
    <watermarkLink value="http://mydomain.com"/>
    </video>
    </category>
</videos>

in this code i want to change the following dynamically with php

    <videoPath value="video.mp4"/>
    <previewImage value="image.jpg"/>

or let me know how can i generate the whole code with php or include in php


Using DomDocument is one option:

$dom = new DomDocument;
$dom->loadXml($xml);
$videoPaths = $dom->getElementsByTagName('videoPath');
foreach ($videoPaths as $videoPath) {
  $videoPath->setAttribute('value', 'newvideo.mp4');
}
$previewImages = $dom->getElementsByTagName('previewImage');
foreach ($previewImages as $previewImage) {
  $previewImage->setAttribute('value', 'newimage.jpg');
}
$xml = $dom->saveXml();

SimpleXML may also suit.

0

精彩评论

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