/// <summary>
        /// Write the Structure/KeyFamilies included in <paramref name="dataStructures"/>
        /// </summary>
        /// <param name="dataStructures">
        /// The list of DSD.
        /// </param>
        private void WriteKeyFamilies(IEnumerable<IDataStructureMutableObject> dataStructures)
        {
            this.WriteStartElement(this.RootNamespace, ElementNameTable.KeyFamilies);
            foreach (IDataStructureMutableObject artefact in dataStructures)
            {
                this.WriteMaintainableArtefact(ElementNameTable.KeyFamily, artefact);
                if (HasComponents(artefact))
                {
                    this.WriteStartElement(this.DefaultPrefix, ElementNameTable.Components);
                    var helper = new CrossSectionalDsdHelper(artefact);

                    //// TODO java 0.9.9 interface issue Missing Position from DimensionMutableBean
                    ////var orderedDimensions = new List<IDimensionMutableObject>(artefact.Dimensions);
                    ////orderedDimensions.Sort((o, mutableObject) => Comparer<int>.Default.Compare(o.Position, mutableObject.Position));
                    foreach (IDimensionMutableObject item in artefact.Dimensions)
                    {
                        this.WriteComponent(item, helper);
                    }

                    foreach (IGroupMutableObject group in artefact.Groups)
                    {
                        this.WriteGroup(group);
                    }

                    if (artefact.PrimaryMeasure != null)
                    {
                        this.WriteComponent(artefact.PrimaryMeasure);
                    }

                    helper.HandleCrossSectionalMeasures(this.WriteComponent);

                    if (artefact.AttributeList != null)
                    {
                        foreach (IAttributeMutableObject attribute in artefact.AttributeList.Attributes)
                        {
                            this.WriteComponent(attribute, helper);
                        }
                    }

                    this.WriteEndElement(); // Components
                }

                this.WriteAnnotations(ElementNameTable.Annotations, artefact.Annotations);
                this.WriteEndElement(); // KeyFamily
            }

            this.WriteEndElement();
        }
        /// <summary>
        /// Write a KeyFamily/Components/Dimensions element from a IDimensionMutableObject object
        /// </summary>
        /// <param name="dimension">
        /// The IDimensionMutableObject object to write
        /// </param>
        /// <param name="helper">
        /// Helper class for SDMX v2.0 cross-sectional
        /// </param>
        private void WriteComponent(IDimensionMutableObject dimension, CrossSectionalDsdHelper helper)
        {
            if (dimension.TimeDimension)
            {
                this.WriteStartElement(this.DefaultPrefix, ElementNameTable.TimeDimension);
            }
            else
            {
                this.WriteStartElement(this.DefaultPrefix, ElementNameTable.Dimension);
                this.TryWriteAttribute(AttributeNameTable.isMeasureDimension, dimension.MeasureDimension);
                this.TryWriteAttribute(AttributeNameTable.isFrequencyDimension, dimension.FrequencyDimension);
            }

            this.WriteComponentAttributes(dimension);
            if (dimension.MeasureDimension)
            {
                this.WriteRepresentation(helper.GetRepresentation(dimension));
            }
            else
            {
                this.WriteRepresentation(dimension.Representation);
            }
            helper.WriteCrossComponentAttributes(dimension, this.TryWriteAttribute);

            //// TODO not supported by the Common API 0.9.9
            ////this.TryWriteAttribute(AttributeNameTable.isCountDimension, dimension.CountDimension);
            ////this.TryWriteAttribute(AttributeNameTable.isEntityDimension, dimension.IsEntityDimension);
            ////this.TryWriteAttribute(AttributeNameTable.isIdentityDimension, dimension.IsIdentityDimension);
            ////this.TryWriteAttribute(
            ////    AttributeNameTable.isNonObservationTimeDimension, dimension.IsNonObservationTimeDimension);
            this.WriteComponentContent(dimension);
            this.WriteEndElement();
        }
        /// <summary>
        /// Write a KeyFamily/Components/Attribute element from a IAttributeMutableObject object
        /// </summary>
        /// <param name="attribute">
        /// The IAttributeMutableObject object to write
        /// </param>
        /// <param name="helper">
        /// The helper.
        /// </param>
        private void WriteComponent(IAttributeMutableObject attribute, CrossSectionalDsdHelper helper)
        {
            this.WriteStartElement(this.DefaultPrefix, ElementNameTable.Attribute);
            this.WriteComponentAttributes(attribute);
            this.WriteRepresentation(attribute.Representation);
            helper.WriteCrossComponentAttributes(attribute, this.TryWriteAttribute);

            /* 
                  <xs:attribute name="attachmentLevel" type="structure:AttachmentLevelType" use="required"/>
                <xs:attribute name="assignmentStatus" type="structure:AssignmentStatusType" use="required"/>
                <xs:attribute name="isTimeFormat" type="xs:boolean" default="false"/>
                <xs:attribute name="isEntityAttribute" type="xs:boolean" default="false"/>
                <xs:attribute name="isNonObservationalTimeAttribute" type="xs:boolean" default="false"/>
                <xs:attribute name="isCountAttribute" type="xs:boolean" default="false"/>
                <xs:attribute name="isFrequencyAttribute" type="xs:boolean" default="false"/>
                <xs:attribute name="isIdentityAttribute" type="xs:boolean" default="false"/>
             */
            this.TryWriteAttribute(
                AttributeNameTable.attachmentLevel, Helper.GetAttachmentLevelV2(attribute.AttachmentLevel));
            this.TryWriteAttribute(AttributeNameTable.assignmentStatus, attribute.AssignmentStatus);
            this.TryWriteAttribute(AttributeNameTable.isTimeFormat, "TimeFormat".Equals(attribute.Id));

            //////this.TryWriteAttribute(AttributeNameTable.isEntityAttribute, attribute.IsEntityAttribute);
            //////this.TryWriteAttribute(
            //////    AttributeNameTable.isNonObservationalTimeAttribute, attribute.IsNonObservationalTimeAttribute);
            //////this.TryWriteAttribute(AttributeNameTable.isCountAttribute, attribute.IsCountAttribute);
            //////this.TryWriteAttribute(AttributeNameTable.isFrequencyAttribute, attribute.IsFrequencyAttribute);
            //////this.TryWriteAttribute(AttributeNameTable.isIdentityAttribute, attribute.IsIdentityAttribute);
            this.WriteComponentContent(attribute);

            /*
             * <xs:element name="AttachmentGroup" type="common:IDType" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="AttachmentMeasure" type="common:IDType" minOccurs="0" maxOccurs="unbounded"/>
             */
            this.TryToWriteElement(this.DefaultNS, ElementNameTable.AttachmentGroup, attribute.AttachmentGroup);

            helper.WriteAttachementMeasures(
                attachmentMeasure =>
                this.TryToWriteElement(this.DefaultNS, ElementNameTable.AttachmentMeasure, attachmentMeasure), 
                attribute.ConceptRef.ChildReference.Id);

            this.WriteEndElement();
        }