dom4: improvement courtesy of @marksteve