/// <summary>
        /// Override - Implementation will call <see cref="DvMediaContainer.UpdateMediaMetadata"/>
        /// if the delegate is non-null. The delegate is executed before the base class
        /// the XML is written. The implementation is also responsible for printing
        /// the XML in such a way that each automapped resource is printed once for each
        /// network interface.
        /// </summary>
        /// <param name="formatter">
        /// A <see cref="ToXmlFormatter"/> object that
        /// specifies method implementations for printing
        /// media objects and metadata.
        /// </param>
        /// <param name="data">
        /// This object should be a <see cref="ToXmlDataDv"/>
        /// object that contains additional instructions used
        /// by this implementation.
        /// </param>
        /// <param name="xmlWriter">
        /// The <see cref="XmlTextWriter"/> object that
        /// will format the representation in an XML
        /// valid way.
        /// </param>
        /// <exception cref="InvalidCastException">
        /// Thrown if the "data" argument is not a <see cref="ToXmlDataDv"/> object.
        /// </exception>
        /// <exception cref="InvalidCastException">
        /// Thrown if the one of the UpdateStoragexxx delegates needs to get executed
        /// whilst the provided value for the metadata is not a PropertyULong instance.
        /// </exception>
        public override void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            if (this.Callback_UpdateMetadata != null)
            {
                this.Callback_UpdateMetadata(this);
            }

            InnerXmlWriter.WriteInnerXml
            (
                this,
                new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties),
                new InnerXmlWriter.DelegateShouldPrintResources(this.PrintResources),
                // Write resources can throw InvalidCastException
                new InnerXmlWriter.DelegateWriteResources(InnerXmlWriterDv.WriteInnerXmlResources),
                new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes),
                formatter,
                (ToXmlData)data,
                xmlWriter
            );
        }
        /// <summary>
        /// Override - Implementation will call <see cref="DvMediaItem.UpdateMediaMetadata"/>
        /// if the delegate is non-null. The delegate is executed before the base class
        /// the XML is written. The implementation is also responsible for printing
        /// the XML in such a way that each automapped resource is printed once for each
        /// network interface.
        /// </summary>
        /// <param name="formatter">
        /// A <see cref="ToXmlFormatter"/> object that
        /// specifies method implementations for printing
        /// media objects and metadata.
        /// </param>
        /// <param name="data">
        /// This object should be a <see cref="ToXmlDataDv"/>
        /// object that contains additional instructions used
        /// by this implementation.
        /// </param>
        /// <param name="xmlWriter">
        /// The <see cref="XmlTextWriter"/> object that
        /// will format the representation in an XML
        /// valid way.
        /// </param>
        /// <exception cref="InvalidCastException">
        /// Thrown if the "data" argument is not a <see cref="ToXmlDataDv"/> object.
        /// </exception>
        /// <exception cref="InvalidCastException">
        /// Thrown if the one of the UpdateStoragexxx delegates needs to get executed
        /// whilst the provided value for the metadata is not a PropertyULong instance.
        /// </exception>
        public override void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            // To prevent constant updating of metadata for a media object,
            // we don't have a callback for updating item metadata, unlike
            // DvMediaContainer. DvMediaItem relies on the parent container
            // to update the metadata of the item.

            ToXmlDataDv txdv = (ToXmlDataDv)data;

            InnerXmlWriter.WriteInnerXml
            (
                this,
                new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties),
                new InnerXmlWriter.DelegateShouldPrintResources(this.PrintResources),
                new InnerXmlWriter.DelegateWriteResources(InnerXmlWriterDv.WriteInnerXmlResources),
                new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes),
                formatter,
                txdv,
                xmlWriter
            );
        }
        /// <summary>
        /// Always prints the full representation as required by the CDS specification.
        /// No custom formatting options are honored, although desired properties
        /// are supported in the data param.
        /// </summary>
        /// <param name="formatter">only options related to CDS-normative formatting are honored</param>
        /// <param name="data">Must be <see cref="ToXmlData"/> instance.</param>
        /// <param name="xmlWriter"></param>
        public void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement(T[_DIDL.Item]);
            xmlWriter.WriteAttributeString(T[_ATTRIB.id], this.ID);
            xmlWriter.WriteAttributeString(T[_ATTRIB.refID], this.m_Underlying.ID);
            xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_Parent.ID);
            xmlWriter.WriteAttributeString(T[_ATTRIB.restricted], "1");

            InnerXmlWriter.WriteInnerXml
            (
                this,
                new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties),
                new InnerXmlWriter.DelegateShouldPrintResources(MediaObject.ShouldPrintResources),
                new InnerXmlWriter.DelegateWriteResources(InnerXmlWriter.WriteInnerXmlResources),
                new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes),
                formatter,
                (ToXmlData)data,
                xmlWriter
            );

            xmlWriter.WriteEndElement();
        }