Recently, I've had the need to load HTML document fragments into
QueryPath. These fragments may or may not be combined later into a
complete HTML template. The issue I'm having though, is that if I
read a file, say, called "test.html" that contiains the following
HTML: "<strong>test</strong>", it will be treated as HTML and the
parser will automatically add additional tags to it to make it a full
page. Since we write XHTML, we would prefer just to parse the
fragment as XML, but then, I think I'd have to an XML declaration to
the top of each fragment which I'm not keen on doing. Below are some
string replacements that I've put in place as a stop-gap solution,
just wondering if anyone on the list knows a way to work around this?
Thanks!
- - - - - -
ob_start();
$html->writeXML();
$buffer = ob_get_clean();
//nasty hack to support html fragments :(
$buffer = str_replace('<?xml version="1.0" standalone="yes"?>', '',
$buffer);
$buffer = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" "
http://www.w3.org/TR/REC-html40/loose.dtd">', '',
$buffer);
$buffer = str_replace('<html>', '', $buffer);
$buffer = str_replace('<body>', '', $buffer);
$buffer = str_replace('</html>', '', $buffer);
$buffer = str_replace('</body>', '', $buffer);