php – SimpleXml how to correctly set encoding and xmins?-ThrowExceptions

Exception or error:

Any ideas on how I can get PHPs SimplXMLElement to kick off with the following?

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="">

The main root will then be:


Or do I use simplexml_load_string() to set it up?

Context: I am extending simpleXmlElement to create some kml files.


Actually, setting the kml xmlns was laughably easy to do:

new simpleXMLElement('<kml xmlns="">

Just how to set encoding=”UTF-8″ that is bothering me, seemingly the kml is acceptable without that, but I’d still like to understand how to do it if pos.

How to solve:
new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>'
                          .'<kml xmlns="">'

Leave a Reply

Your email address will not be published. Required fields are marked *