我根据表单上的用户输入将属性放在XML元素中。尝试抛出层次结构请求错误。我没有看到错误。我做错了吗?我不是每日程序员。
<html>
<head>
<title></title>
</head>
<body>
<?php
if (isset($_REQUEST['ok'])) {
try {
$xml = new DOMDocument("1.0", "UTF-8");
$xml->load("PhoneBook.xml");
$xmlYealink = $xml->getElementsByTagName("YealinkIPPhoneBook")->item(0);
$xml_Menu = $xml->createElement("Menu");
$xml_Menu->setAttribute("Name", "Drivers");
$xml_Unit = $xml->createElement("Unit");
$xml_Unit->setAttribute("Name", $_REQUEST['name']);
$xml_Unit->setAttribute("Phone3", $_REQUEST['phone3']);
$xml_Unit->setAttribute("Phone2", $_REQUEST['phone2']);
$xml_Unit->setAttribute("Phone1", $_REQUEST['phone1']);
$xml_Unit->appendChild($xml_Unit);
$xml_Menu->appendChild($xml_Menu);
$xml->save("PhoneBook.xml");
} catch (Exception $e) {
echo $e->getMessage();
}
}
?>
<form method="post">
<label for="name">Name</label> <input type="text" name="name" /> </br>
<label for="phone3">Extension</label> <input type="text" name="phone3" /> </br>
<label for="phone2">Direct</label> <input type="text"name="phone2" /> </br>
<label for="phone1">Cellular</label> <input type="text" name="phone1" /> </br>
<input type="submit" name="ok" value="Submit Entry">
</form>
</body>
</html>