NextSibling() segfault when called on the root node, so add a check