Added  check for qi_query, as this could be a QF
Fixed xml template may signal an error and leave xenc initialized with non-box