$xml = ''; $book = new SimpleXMLElement($xml); echo $book->getName(); // Output: book PHP for Beginners
$xml = 'In this example, we create a SimpleXMLElement object from an XML string that contains a fruit element with child elements name and color. We then use a foreach loop to iterate through the child elements and use the getName method to retrieve their names and display them along with their values. Package/library: SimpleXML is a part of the PHP core, so no external library or package is required.'; $fruit = new SimpleXMLElement($xml); foreach ($fruit->children() as $child) { echo $child->getName() . ": " . $child . "\n"; } Apple Red