+ // If the original had xmlns or xml:lang attributes on the
+ // <html>, we seen to end up with duplicates, which causes
+ // parse errors. Remove em!
+ //
+ // For some reason we have to iterate and remove them twice,
+ // *plus* they don't show up on hasAttribute() or removeAttribute().
+ // This might be some weird bug in PHP or libxml2, uncertain if
+ // it affects other folks consistently.
+ $root = $dom->documentElement;
+ foreach ($root->attributes as $i => $x) {
+ if ($i == 'xmlns' || $i == 'xml:lang') {
+ $root->removeAttributeNode($x);
+ }
+ }
+ foreach ($root->attributes as $i => $x) {
+ if ($i == 'xmlns' || $i == 'xml:lang') {
+ $root->removeAttributeNode($x);
+ }
+ }
+