/// <summary>
        /// Writes the <paramref name="element"/> with <paramref name="writer"/>. The element name is taken from <see cref="IXmlElement.GetXmlName()"/>.
        /// </summary>
        /// <param name="writer">The XML writer</param>
        /// <param name="element">The object to write</param>
        /// <param name="parentElementName">the parent element. If not null, <paramref name="element"/> is wrapped in an element with this name</param>
        internal static void WriteElement(XmlWriter writer, IXmlElement element, string parentElementName = null)
        {
            if (!String.IsNullOrEmpty(parentElementName))
            {
                writer.WriteStartElement(parentElementName);
            }

            writer.WriteStartElement(element.GetXmlName());
            element.WriteXml(writer);
            writer.WriteEndElement();

            if (!String.IsNullOrEmpty(parentElementName))
            {
                writer.WriteEndElement();
            }
        }