item 、英語の単語とヘブライ語の単語を使用して、xmlファイルに新しいレコードを書き込んでいます。
しかし、
$newWord->appendChild($prop.$new_line);
この行により、
「クラスDOMElementのオブジェクトを文字列に変換できませんでした」というエラーが発生します
パラメータ$new_lineはに等しい$new_line = "\n";
。
ここで何が恋しいですか?
私のコードは次のとおりです。
<?php
/*$wordH=$_GET['varHeb'];
$wordE=$_GET['varEng'];*/
$wordH="newhebWord";
$wordE="newengWord";
$new_line = "\n";
$doc='';
if(!$doc)
{
$doc = new DOMDocument();
// we want a nice output
$doc->formatOutput = true;
$doc->load('Dictionary_user.xml');
}
$Dictionary_user = $doc->documentElement;
$newWord = $doc->createElement('newWord');
$prop = $doc->createElement('Heb', $wordH);
$newWord->appendChild($prop.$new_line);
$prop = $doc->createElement('Eng',$wordE);
$newWord->appendChild($prop.$new_line);
$Dictionary_user->childNodes->item(0)->parentNode->insertBefore($newWord,$Dictionary_user->childNodes->item(0));
header("Content-type: text/xml");
$doc->save("Dictionary_user.xml");
echo $doc->saveXML();
?>