我正在用 to 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();
?>