PHP文档未按预期工作

PHP文档未按预期工作,php,domdocument,Php,Domdocument,因此,我尝试使用PHPDomDocument扩展来编写XML文档。我已经编写了所有代码,但新XML文件中出现的唯一节点是XML头 代码如下: //vars $history_location="w1/history_files/" . md5($time) . md5(rand(0,1000)) . rand(0,1000) . '.xml'; $id=2; $airline="Aero Test Ltd."; $aircraft="Boeing 747-400"; $engine="Rolls

因此,我尝试使用PHPDomDocument扩展来编写XML文档。我已经编写了所有代码,但新XML文件中出现的唯一节点是XML头

代码如下:

//vars
$history_location="w1/history_files/" . md5($time) . md5(rand(0,1000)) . rand(0,1000) . '.xml';
$id=2;
$airline="Aero Test Ltd.";
$aircraft="Boeing 747-400";
$engine="Rolls-Royce RB211-524H2-T";
$f=5;
$c=25;
$yp=40;
$y=560;
//xml history file
$xml=new DOMDocument();
$xml->formatOutput=true;
//tags
$tag_history=$xml->createElement("history");
$tag_preface=$xml->createElement("preface");
$tag_l1=$xml->createElement("l1", "This is the history file for aircraft " . $id . ".");
$tag_l2=$xml->createElement("l2", "Generated: " . date("F d Y H:i:s", $time) . ".");
$tag_l3=$xml->createElement("l3", "Last Updated: " . date("F d Y H:i:s", $time) . ".");
$tag_body=$xml->createElement("body");
$tag_item=$xml->createElement("item");
$tag_airline=$xml->createElement("airline", $airline);
$tag_aircraft=$xml->createElement("aircraft", $aircraft);
$tag_engine=$xml->createElement("engine", $engine2);
$tag_config=$xml->createElement("config", $f . $c . $yp . $y);
//attr
$attr_name=$xml->createAttribute("name");
$attr_name->value="purchase";
$attr_date=$xml->createAttribute("date");
$attr_date->value=date("F d Y H:i:s", $time);
//sort
$tag_history->appendChild($tag_preface);
$tag_preface->appendChild($tag_l1);
$tag_preface->appendChild($tag_l2);            
$tag_preface->appendChild($tag_l3);
$tag_history->appendChild($tag_body);
$tag_body->appendChild($tag_item);
$tag_item->appendChild($attr_name);
$tag_item->appendChild($attr_date);
$tag_item->appendChild($tag_airline);
$tag_item->appendChild($tag_aircraft);
$tag_item->appendChild($tag_engine);
$tag_item->appendChild($tag_config);
//save
$xml->save($history_location);
所有保存到文件中的内容都是

我查阅了各种各样的文档、问题和谷歌搜索页面,但没有找到任何解释或解决问题的方法

到底发生了什么?我是怎么搞砸的

提前感谢,,
~Hom

在调用
save()
之前,您错过了以下步骤:

$xml->appendChild($tag_history);