/// <summary>
        /// Write QueryStructureResponse
        /// </summary>
        /// <param name="response">
        /// The QueryStructureResponseBean to write
        /// </param>
        private void WriteQueryStructureResponse(IQueryStructureResponseInfo response)
        {
            this.WriteStartElement(ElementNameTable.QueryStructureResponse);

            this.WriteStatusMessage(response.StatusMessage);

            var structureWriter = new StructureWriterV2(this.SdmxMLWriter);
            structureWriter.SetTopElementsNS(this.Namespaces.Registry);
            structureWriter.WriteStructure(response.Structure, null);

            this.WriteEndElement(); // </QueryStructureResponse>
        }
        public void TestWriteReadBigCodeList(int count)
        {
            string countStr = count.ToString(CultureInfo.InvariantCulture);
            ICodelistMutableObject codelist = new CodelistMutableCore();
            codelist.Id = "CL_K" + countStr;
            codelist.AgencyId = "TEST";
            codelist.AddName("en", "Test CL with " + countStr);
            for (int i = 0; i < count; i++)
            {
                ICodeMutableObject code = new CodeMutableCore();
                code.Id = i.ToString(CultureInfo.InvariantCulture);
                code.AddName("en", "Code " + code.Id);
                codelist.AddItem(code);
            }

            IMutableObjects mutableObjects = new MutableObjectsImpl();
            mutableObjects.AddCodelist(codelist);
            var sw = new Stopwatch();
            string output = string.Format(CultureInfo.InvariantCulture, "big-codelist-{0}.xml", countStr);
            sw.Start();
            using (XmlWriter writer = XmlWriter.Create(output, new XmlWriterSettings { CloseOutput = true, Indent = true }))
            {
                var structureWriter = new StructureWriterV2(writer);
                structureWriter.WriteStructure(mutableObjects, new HeaderImpl("ZZ9", "ZZ9"));
            }

            sw.Stop();
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Writing {0} took {1}", countStr, sw.Elapsed));

            sw.Reset();
            sw.Start();
            XmlReaderSettings settings = XMLParser.GetSdmxXmlReaderSettings(SdmxSchemaEnumType.VersionTwo);
            settings.ValidationEventHandler += OnValidationEventHandler;
            var structureReader = new StructureReaderV2();
            settings.NameTable = NameTableCache.Instance.NameTable;
            using (XmlReader reader = XmlReader.Create(output, settings))
            {
                IMutableObjects res = structureReader.Read(reader);
                Assert.NotNull(res);
            }

            sw.Stop();
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Reading {0} took {1}", countStr, sw.Elapsed));
        }
        public void TestStructureReaderWriteV2(string file)
        {
            var structureReader = new StructureReaderV2();
            var fileInfo = new FileInfo(file);
            IMutableObjects mutableObjects;
            XmlReaderSettings settings = XMLParser.GetSdmxXmlReaderSettings(SdmxSchemaEnumType.VersionTwo);
            settings.ValidationEventHandler += OnValidationEventHandler;
            ISdmxObjects structure;
            using (FileStream stream = fileInfo.OpenRead())
            {
                settings.NameTable = NameTableCache.Instance.NameTable;
                using (XmlReader reader = XmlReader.Create(stream, settings))
                {
                    mutableObjects = structureReader.Read(reader);
                    Assert.NotNull(mutableObjects);
                    structure = mutableObjects.ImmutableObjects;
                    Assert.NotNull(structure);
                }
            }

            string output = string.Format(CultureInfo.InvariantCulture, "output-{0}", fileInfo.Name);
            using (XmlWriter writer = XmlWriter.Create(output, new XmlWriterSettings { CloseOutput = true, Indent = true }))
            {
                var structureWriter = new StructureWriterV2(writer);
                structureWriter.WriteStructure(mutableObjects, new HeaderImpl("ZZ9", "ZZ9"));
            }

            using (XmlReader reader = XmlReader.Create(output, settings))
            {
                IMutableObjects newMutableObjects = structureReader.Read(reader);
                Assert.NotNull(newMutableObjects);
                ISdmxObjects newStructure = newMutableObjects.ImmutableObjects;
                Assert.NotNull(newStructure);
                Assert.AreEqual(newStructure.CategorySchemes.Count, structure.CategorySchemes.Count);
                Assert.AreEqual(newStructure.Codelists.Count, structure.Codelists.Count);
                Assert.AreEqual(newStructure.ConceptSchemes.Count, structure.ConceptSchemes.Count);
                Assert.AreEqual(newStructure.Dataflows.Count, structure.Dataflows.Count);
                Assert.AreEqual(newStructure.DataStructures.Count, structure.DataStructures.Count);
                Assert.AreEqual(newStructure.HierarchicalCodelists.Count, structure.HierarchicalCodelists.Count);

                CompareArtefacts(newStructure.CategorySchemes, structure.GetCategorySchemes);
                CompareArtefacts(newStructure.Codelists, structure.GetCodelists);
                CompareArtefacts(newStructure.ConceptSchemes, structure.GetConceptSchemes);
                CompareArtefacts(newStructure.Dataflows, structure.GetDataflows);
                CompareArtefacts(newStructure.DataStructures, structure.GetDataStructures);
                CompareArtefacts(newStructure.HierarchicalCodelists, structure.GetHierarchicalCodelists);
            }

            // compare against StructureWorkspace from SdmxStructureParser
            var parsingManager = new StructureParsingManager(SdmxSchemaEnumType.VersionTwo);
            using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(fileReadableDataLocation);
                Assert.NotNull(structureWorkspace);
                ISdmxObjects newStructure = structureWorkspace.GetStructureObjects(false);
                Assert.NotNull(newStructure);
                Assert.AreEqual(newStructure.CategorySchemes.Count, structure.CategorySchemes.Count);
                Assert.AreEqual(newStructure.Codelists.Count, structure.Codelists.Count);
                Assert.AreEqual(newStructure.ConceptSchemes.Count, structure.ConceptSchemes.Count);
                Assert.AreEqual(newStructure.Dataflows.Count, structure.Dataflows.Count);
                Assert.AreEqual(newStructure.DataStructures.Count, structure.DataStructures.Count);
                Assert.AreEqual(newStructure.HierarchicalCodelists.Count, structure.HierarchicalCodelists.Count);

                CompareArtefacts(newStructure.CategorySchemes, structure.GetCategorySchemes);
                CompareArtefacts(newStructure.Codelists, structure.GetCodelists);
                CompareArtefacts(newStructure.ConceptSchemes, structure.GetConceptSchemes);
                CompareArtefacts(newStructure.Dataflows, structure.GetDataflows);
                CompareArtefacts(newStructure.DataStructures, structure.GetDataStructures);
                CompareArtefacts(newStructure.HierarchicalCodelists, structure.GetHierarchicalCodelists);
            }
        }