これは、コメント要素を作成する関数 (コメントを処理するクラス内) です。
function add($id,$message){
$newcomment = $this->source->addChild('comment');
$newcomment->addAttribute('user',$id);
$newcomment->addAttribute('timestamp',time());
$newcomment = $message; // <--------- fail
$this->source->asXML($this->save);
return(true);
}
これはすべて機能しますが、指している行で何をしているのかは明らかにわかりません。しかし、私は基本的に次のようにコメント要素にメッセージを入れたいと思っています:
<comments>
<comment id="12345678" timestamp="1355812061">
Hey friend, what's up?
</comment>
<comment id="87654321" timestamp="1355813155">
Nothing much, just have this problem with simpleXML
</comment>
</comments>
しかし、メッセージが設定されていないことを除いて、私が持っているものは機能します。
だから私の質問は、これは可能ですか?もしそうなら、私は何をしなければなりませんか?