Utility method to convert object to XmlElement, or XElement