Refactored to better reuse the code moved to XmlHelper