Prevent while() from causing potential infinite loops

If xml files don't have proper close tags, don't generate an infinite
loop in our library.