Refactored XML validation