/// <summary>
        /// Builds the DSD.
        /// </summary>
        /// <returns>The DSD.</returns>
        private static IDataStructureObject BuildDsd(IMaintainableRefObject dsdRef, int dimensions)
        {
            IDataStructureMutableObject dsdMutableObject = new DataStructureMutableCore
                                                               {
                                                                   AgencyId = dsdRef.AgencyId,
                                                                   Id = dsdRef.MaintainableId,
                                                                   Version = dsdRef.HasVersion() ? dsdRef.Version : "1.0"
                                                               };
            dsdMutableObject.AddName("en", "Test data");

            // FREQ="Q" ADJUSTMENT="N" STS_ACTIVITY="A" 
            dsdMutableObject.AddDimension(
                new StructureReferenceImpl(agencyId: dsdRef.AgencyId, maintainableId: "TEST_CS", version: "1.0", targetStructureEnum: SdmxStructureEnumType.Concept, identfiableIds: "FREQ"),
                new StructureReferenceImpl("SDMX", "CL_FREQ", "1.0", SdmxStructureEnumType.CodeList));

            var groupMutableCore = new GroupMutableCore() { Id = "Sibling" };
            dsdMutableObject.AddGroup(groupMutableCore);
            for (int i = 0; i < dimensions; i++)
            {
                string id = "DIM" + i.ToString(CultureInfo.InvariantCulture);
                var dim = dsdMutableObject.AddDimension(
                    new StructureReferenceImpl(
                        agencyId: dsdRef.AgencyId,
                        maintainableId: "TEST_CS",
                        version: "1.0",
                        targetStructureEnum: SdmxStructureEnumType.Concept,
                        identfiableIds: id), codelistRef: new StructureReferenceImpl(dsdRef.AgencyId, "CL_" + id, "1.0", SdmxStructureEnumType.CodeList));
                groupMutableCore.DimensionRef.Add(id);
            }

            dsdMutableObject.AddDimension(
                new DimensionMutableCore
                    {
                        ConceptRef =
                            new StructureReferenceImpl(
                            agencyId: dsdRef.AgencyId,
                            maintainableId: "TEST_CS",
                            version: "1.0",
                            targetStructureEnum: SdmxStructureEnumType.Concept,
                            identfiableIds: "TIME_PERIOD"),
                        TimeDimension = true
                    });

            dsdMutableObject.AddPrimaryMeasure(
                new StructureReferenceImpl(agencyId: dsdRef.AgencyId, maintainableId: "TEST_CS", version: "1.0", targetStructureEnum: SdmxStructureEnumType.Concept, identfiableIds: "OBS_VALUE"));
            
            var obsStatus =
                dsdMutableObject.AddAttribute(
                    new StructureReferenceImpl(agencyId: dsdRef.AgencyId, maintainableId: "TEST_CS", version: "1.0", targetStructureEnum: SdmxStructureEnumType.Concept, identfiableIds: "OBS_STATUS"),
                    new StructureReferenceImpl(dsdRef.AgencyId, "CL_OBS_STATUS", "1.0", SdmxStructureEnumType.CodeList));
            obsStatus.AttachmentLevel = AttributeAttachmentLevel.Observation;
            obsStatus.AssignmentStatus = "Mandatory";

            var obsConf =
                dsdMutableObject.AddAttribute(
                    new StructureReferenceImpl(agencyId: dsdRef.AgencyId, maintainableId: "TEST_CS", version: "1.0", targetStructureEnum: SdmxStructureEnumType.Concept, identfiableIds: "OBS_CONF"),
                    new StructureReferenceImpl(dsdRef.AgencyId, "CL_OBS_CONF", "1.0", SdmxStructureEnumType.CodeList));
            obsConf.AttachmentLevel = AttributeAttachmentLevel.Observation;
            obsConf.AssignmentStatus = "Conditional";

            AddCodedAttribute(dsdMutableObject, "UNIT_MULT");
            AddCodedAttribute(dsdMutableObject, "UNIT");
            AddUnCodedAttribute(dsdMutableObject, "TITLE_COMPL");

            return dsdMutableObject.ImmutableInstance;
        }
        protected void btnAddGroup_Click(object sender, EventArgs e)
        {
            if (!ValidateGroupData())
            {
                OpenAddGroupPopUp();
                return;
            }

            IGroupMutableObject group = new GroupMutableCore();
            group.Id = txtGroupID.Text;

            foreach (ListItem li in lbGroupDimension.Items)
            {
                if (li.Selected)
                    group.DimensionRef.Add(li.Value);
            }

            try
            {

                _dsdMutable.AddGroup(group);
                SetDsdToSession();
                SetGroupTab(_dsdMutable.ImmutableInstance);

                txtGroupID.Text = "";
                lbGroupDimension.ClearSelection();

                Utils.ForceBlackClosing();
            }
            catch (Exception ex)
            {
                _dsdMutable.Groups.Remove(group);
                OpenAddGroupPopUp();
                Utils.ShowDialog(ex.Message, 600, Resources.Messages.err_add_group);
            }
        }
        /// <summary>
        /// Handles the KeyFamily element child elements
        /// </summary>
        /// <param name="parent">
        /// The parent IDataStructureMutableObject object
        /// </param>
        /// <param name="localName">
        /// The name of the current xml element
        /// </param>
        /// <returns>
        /// The <see cref="StructureReaderBaseV20.ElementActions"/>.
        /// </returns>
        private ElementActions HandleChildElements(ICrossSectionalDataStructureMutableObject parent, object localName)
        {
            ElementActions actions = null;
            if (NameTableCache.IsElement(localName, ElementNameTable.Dimension))
            {
                var dimension = new DimensionMutableCore();
                ParseAttributes(parent, dimension, this.Attributes);
                parent.AddDimension(dimension);
                actions = this.BuildElementActions(dimension, this.HandleChildElements, DoNothing);
            }
            else if (NameTableCache.IsElement(localName, ElementNameTable.TimeDimension))
            {
                var timeDimension = new DimensionMutableCore { TimeDimension = true, Id = DimensionObject.TimeDimensionFixedId };
                ParseAttributes(parent, timeDimension, this.Attributes);
                parent.AddDimension(timeDimension);
                actions = this.BuildElementActions(timeDimension, this.HandleChildElements, DoNothing);
            }
            else if (NameTableCache.IsElement(localName, ElementNameTable.PrimaryMeasure))
            {
                var measure = new PrimaryMeasureMutableCore();
                ParseComponentBaseAttributes(parent, measure, this.Attributes);
                parent.PrimaryMeasure = measure;
                actions = this.BuildElementActions(measure, this.HandleChildElements, DoNothing);
            }
            else if (NameTableCache.IsElement(localName, ElementNameTable.CrossSectionalMeasure))
            {
                var measure = new CrossSectionalMeasureMutableCore();
                ParseAttributes(parent, measure, this.Attributes);
                parent.AddCrossSectionalMeasures(measure);
                actions = this.BuildElementActions(measure, this.HandleChildElements, DoNothing);
            }
            else if (NameTableCache.IsElement(localName, ElementNameTable.Attribute))
            {
                var attribute = new AttributeMutableCore();
                ParseAttributes(parent, attribute, this.Attributes);
                parent.AddAttribute(attribute);
                actions = this.BuildElementActions(attribute, this.HandleChildElements, this.HandleTextChildElement);
            }
            else if (NameTableCache.IsElement(localName, ElementNameTable.Components))
            {
                //// Component element contains the rest of elements so we use the same action again.
                actions = this.BuildElementActions(parent, this.HandleChildElements, DoNothing);
            }
            else if (NameTableCache.IsElement(localName, ElementNameTable.Group))
            {
                var groupMutableCore = new GroupMutableCore();
                ParseAttributes(groupMutableCore, this.Attributes);
                parent.AddGroup(groupMutableCore);
                actions = this.BuildElementActions(groupMutableCore, this.HandleAnnotableChildElements, this.HandleTextChildElement);
            }

            return actions;
        }