- This php script is responsible for updating the content of our chat room
- The messages inside the chat room are stored in a single XML file called chatroom.xml located in the server
- When it receives the input coming from client.php, it will add the new message to the end of the XML file
- A new message consists of two values: name and message content
- The following format is used for a message in the XML file
<message name="... name here ...">... message content here ...</message>
- You need to add the code for adding a message to the XML file in this lab
- Here is the content of XML file chatroom.xml for the chat messages in the interface figure above

- The name is retrieved from the cookie set in login.php and the content is retrieved from form data
- To open an XML file, you can use the following:
$xmlh->openFile();
- Then we can add a new message element to the messages group by:
$messages_element = $xmlh->getElement("messages");
$message_element = $xmlh->addElement($messages_element, "message");
- Then you can add the name and the text message:
$xmlh->setAttribute($message_element, "name", $name);
$xmlh->addText($message_element, $message);
- Remember to save it:
$xmlh->saveFile();
- Again, after updating the chatroom.xml, the page is redirected back to client.php for the next message input