diff --git a/render/html.c b/render/html.c
index cbda8682d..8a1f67542 100644
--- a/render/html.c
+++ b/render/html.c
@@ -570,8 +570,10 @@ bool html_head(struct content *c, xmlNode *head)
xmlNode *node;
xmlChar *s;
- for (node = xmlFirstElementChild(head); node != 0;
- node = xmlNextElementSibling(node)) {
+ for (node = head->children; node != 0; node = node->next) {
+ if (node->type != XML_ELEMENT_NODE)
+ continue;
+
if (c->title == NULL && strcmp((const char *) node->name,
"title") == 0) {
xmlChar *title = xmlNodeGetContent(node);