$xml = new SimpleXMLElement(''); $xml->addChild('item', 'Hello World'); echo $xml->asXML();
- Hello World
$xml = new SimpleXMLElement(''); $item = $xml->addChild('item'); $item->addAttribute('id', 1); $item->addAttribute('name', 'apple'); echo $xml->asXML();
This method is useful when you want to add an element with attributes. Package library: This method belongs to the PHP core library and does not require any additional package or library.