"; // children() return children of the current node foreach ($xmlObj->children() as $child) { echo $child->name . ", " . $child->email . ", " . $child->phone . ", " . $child->age . "
"; } echo "
"; // children() return children of the current node foreach ($xmlObj->children() as $obj) { foreach ($obj as $child) { echo $child->getName() . " = " . $child . "
"; } } echo "
"; /////////////////////////////////////////// // Work with XML document that has attributes $xmlObj = simplexml_load_file("data/friends-2.xml"); // children() return children of the current node foreach ($xmlObj->children() as $child) { // get all attributes attached to this child foreach ($child->attributes() as $attrName => $attrValue) { echo $attrName . "=" . $attrValue . " " ; } echo "
    "; echo $child->name . ", " . $child->email . ", " . $child->phone . ", " . $child->age . "
"; } ?>