if (!checkEmail($email, $xml)) { echo "false"; } else { //$customers = $xml->getElementsByTagName('Customers'); //$customers = $customers->item(0); //OR $firstElement = $xml->firstChild; // add new node into root $customer = $xml->createElement('customer'); $customer = $firstElement->appendChild($customer); addANodeValue('id', $customerId, $customer, $xml); addANodeValue('firstname', $firstname, $customer, $xml); addANodeValue('lastname', $lastname, $customer, $xml); addANodeValue('password', $password, $customer, $xml); addANodeValue('email', $email, $customer, $xml); addANodeValue('phone', $phone, $customer, $xml); $strXml = $xml->saveXML(); $xml->save($filePath); echo "true"; } } function addANodeValue($nodeChildName, $value, $nodeParent, $root) { $node = $root->createElement($nodeChildName); $node = $nodeParent->appendChild($node); $value_node = $root->createTextNode($value); $value_node = $node->appendChild($value_node); } //check existing email function checkEmail($email, $xml) {
function toXml($shop_cart) { $newDoc = new DOMDocument("1.0"); $root = $newDoc->createElement("items"); $root = $newDoc->appendChild($root); //$newDoc->FormatOutput = true; foreach ($shop_cart as $id => $ItemDetail) { $itemNode = $newDoc->createElement("item"); $itemNode = $root->appendChild($itemNode); //add item tag inside items addANodeValue("id", $id, $itemNode, $newDoc); addANodeValue("price", $ItemDetail["price"], $itemNode, $newDoc); addANodeValue("quantity", $ItemDetail["qty"], $itemNode, $newDoc); } $strXml = $newDoc->saveXML(); return $strXml; }