Hi, I'm trying to use SimpleXML to output a well-formed XHTML document. I'm doing it like this:
$pbDoc = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$myTitle.'</title>
<!-- Other headers -->
</head>
</html>');
After I have created the document, I want to output pretty readable code, so I'm using DOM module like this:
$dom = new DOMDocument();
$dom->loadXML($pbDoc->asXML());
$dom->formatOutput = true;
echo $dom->saveXML();
Now, there are two strange things that bother me, and I wonder whether this behaviour is normal and how to disable it, if possible.
presence of DOCTYPE causes
$pbDoc->asXML()
to add an unneeded meta tag right after the opening<head>
tag:<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Why?
- for some reason, DOM module doesn't indent code at all for me (though it does that very well with a different document, which is XML, and not XHTML).
Could anyone enlighten me about where I may be wrong and how to get rid of these annoyances?