2

XMLファイルから広告をロードするJwプレーヤーアドトノミープラグインを使用して、自分のWebサイトで使用するカスタムプラグインを作成しています。ただし、ファイル内のノードを更新する方法がわかりません。単純なxmlを使用してみましたが、更新方法がわかりません。どの実装も高く評価されています。ありがとう。これがxmlファイルです。

<xml>
<plugins>adtimage</plugins>
<adtimage.graphic>http://mysite/default.png</adtimage.graphic>
<adtimage.link>http://targetsite.com</adtimage.link>
<adtimage.positions>pre,post</adtimage.positions>
<adtimage.onpause>true</adtimage.onpause>
<adtimage.txt>Advertisement</adtimage.txt>
<adtimage.btntxt>Click to continue with video</adtimage.btntxt>
</xml>

私のコードはここにあります。

<?php
$xml = simplexml_load_file("test.xml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
{
 echo $child->getName() . ": " . $child . "<br />";

 /*
   TO DO
   change the node value of 
   <adtimage.graphic>http://mysite/default.png</adtimage.graphic>
   to
   <adtimage.graphic>http://stackoverflow.com</adtimage.graphic>
 */
 }
?>
4

1 に答える 1

1

あなたはこれを使うことができます

//Load XML
$xml = simplexml_load_file("test.xml");

// Modify a node
$xml->{"adtimage.graphic"} = 'http://stackoverflow.com/adtimage.graphic';

// Saving the whole modified XML to a new filename
$xml->asXml('updated.xml');

出力例'updated.xml'

<?xml version="1.0"?>
<xml>
<plugins>adtimage</plugins>
<adtimage.graphic>http://stackoverflow.com/adtimage.graphic</adtimage.graphic>
<adtimage.link>http://targetsite.com</adtimage.link>
<adtimage.positions>pre,post</adtimage.positions>
<adtimage.onpause>true</adtimage.onpause>
<adtimage.txt>Advertisement</adtimage.txt>
<adtimage.btntxt>Click to continue with video</adtimage.btntxt>
</xml>
于 2012-08-02T09:50:51.840 に答える