Load('root.xml'); $child2 = $xml_doc->getElementsByTagName('child2')->item(0); $newattribute=$xml_doc->createAttribute('name'); $child2 -> appendChild($newattribute); $test = $xml_doc->save("root.xml"); echo "New Attribute Created" ?>