Fix namespace detection for edge cases (empty/non-standard XML documents).