private static NatureAreaType ParseNatureAreaType(XElement xElement)
        {
            var natureAreaType = new NatureAreaType();

            if (xElement == null)
            {
                return(natureAreaType);
            }
            var natureAreaTypeCodes = NinXmlParser.GetChildElements(xElement, "kode", TillatAntall.AkkuratEn);

            natureAreaType.Code = natureAreaTypeCodes[0].Value;

            var natureAreaTypeSurveyers =
                NinXmlParser.GetChildElements(xElement, "kartlegger", TillatAntall.MaksimaltEn);

            if (natureAreaTypeSurveyers.Count == 1)
            {
                natureAreaType.Surveyer = NinXmlParser.ParseContact(natureAreaTypeSurveyers[0]);
            }

            var natureAreaTypeSurveyeds =
                NinXmlParser.GetChildElements(xElement, "kartlagtDato", TillatAntall.MaksimaltEn);

            if (natureAreaTypeSurveyeds.Count == 1)
            {
                natureAreaType.Surveyed = Convert.ToDateTime(natureAreaTypeSurveyeds[0].Value);
            }

            var natureAreaTypeShares = NinXmlParser.GetChildElements(xElement, "andel", TillatAntall.AkkuratEn);

            natureAreaType.Share = double.Parse(natureAreaTypeShares[0].Value, CultureInfo.InvariantCulture);

            var natureAreaTypeCustomVariables = NinXmlParser.GetChildElements(xElement, "egendefinerteVariabler",
                                                                              TillatAntall.NullEllerFlere);

            foreach (var natureAreaTypeCustomVariable in natureAreaTypeCustomVariables)
            {
                natureAreaType.CustomVariables.Add(ParseCustomVariable(natureAreaTypeCustomVariable));
            }

            var natureAreaTypeAdditionalVariables = NinXmlParser.GetChildElements(xElement, "tilleggsVariabler",
                                                                                  TillatAntall.NullEllerFlere);

            foreach (var natureAreaTypeAdditionalVariable in natureAreaTypeAdditionalVariables)
            {
                var natureAreaTypeAdditionalDescriptionVariables = NinXmlParser.GetChildElements(
                    natureAreaTypeAdditionalVariable, "Beskrivelsesvariabel", TillatAntall.AkkuratEn);
                natureAreaType.AdditionalVariables.Add(
                    ParseDescriptionVariable(natureAreaTypeAdditionalDescriptionVariables[0]));
            }

            return(natureAreaType);
        }
        public static Dataleveranse ParseDataleveranse(XDocument dataDeliveryXml)
        {
            var dataDelivery = new Dataleveranse();

            if (dataDeliveryXml.Root == null)
            {
                return(dataDelivery);
            }
            var dataDeliveryNames =
                NinXmlParser.GetChildElements(dataDeliveryXml.Root, "navn", TillatAntall.AkkuratEn);

            dataDelivery.Name = dataDeliveryNames[0].Value;

            var dataDeliveryDeliveryDates = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "leveranseDato",
                                                                          TillatAntall.AkkuratEn);

            dataDelivery.DeliveryDate = Convert.ToDateTime(dataDeliveryDeliveryDates[0].Value);

            var dataDeliveryOperators =
                NinXmlParser.GetChildElements(dataDeliveryXml.Root, "operatoer", TillatAntall.AkkuratEn);

            dataDelivery.Operator = NinXmlParser.ParseContact(dataDeliveryOperators[0]);

            var dataDeliveryMetadatas =
                NinXmlParser.GetChildElements(dataDeliveryXml.Root, "metadata", TillatAntall.AkkuratEn);

            dataDelivery.Metadata = ParseMetadata(dataDeliveryMetadatas[0]);

            var dataDeliveryReasonForChanges = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "grunnForEndring",
                                                                             TillatAntall.MaksimaltEn);

            if (dataDeliveryReasonForChanges.Count == 1)
            {
                dataDelivery.ReasonForChange = dataDeliveryReasonForChanges[0].Value;
            }

            var dataDeliveryDescriptions = NinXmlParser.GetChildElements(dataDeliveryXml.Root, "beskrivelse",
                                                                         TillatAntall.MaksimaltEn);

            if (dataDeliveryDescriptions.Count == 1)
            {
                dataDelivery.Description = dataDeliveryDescriptions[0].Value;
            }

            return(dataDelivery);
        }
        private static DescriptionVariable ParseDescriptionVariable(XElement xElement)
        {
            var descriptionVariable = new DescriptionVariable();

            if (xElement == null)
            {
                return(descriptionVariable);
            }
            var natureAreaTypeCodes = NinXmlParser.GetChildElements(xElement, "kode", TillatAntall.AkkuratEn);

            (descriptionVariable).Code = natureAreaTypeCodes[0].Value;

            var descriptionVariableSurveyers =
                NinXmlParser.GetChildElements(xElement, "kartlegger", TillatAntall.MaksimaltEn);

            if (descriptionVariableSurveyers.Count == 1)
            {
                descriptionVariable.Surveyer = NinXmlParser.ParseContact(descriptionVariableSurveyers[0]);
            }

            var descriptionVariableSurveyeds =
                NinXmlParser.GetChildElements(xElement, "kartlagtDato", TillatAntall.MaksimaltEn);

            if (descriptionVariableSurveyeds.Count == 1)
            {
                descriptionVariable.Surveyed = Convert.ToDateTime(descriptionVariableSurveyeds[0].Value);
            }

            var descriptionVariableValues =
                NinXmlParser.GetChildElements(xElement, "verdi", TillatAntall.AkkuratEn);

            (descriptionVariable).Value = descriptionVariableValues[0].Value;

            var descriptionVariableDescriptions =
                NinXmlParser.GetChildElements(xElement, "beskrivelse", TillatAntall.MaksimaltEn);

            if (descriptionVariableDescriptions.Count == 1)
            {
                (descriptionVariable).Description = descriptionVariableDescriptions[0].Value;
            }
            return(descriptionVariable);
        }
        private static Metadata ParseMetadata(XElement xElement)
        {
            var metadata = new Metadata();

            if (xElement == null)
            {
                return(metadata);
            }
            var metadataElement = NinXmlParser.GetChildElements(xElement, "Metadata", TillatAntall.AkkuratEn);

            var e0 = metadataElement[0];
            var metadataUniqueIds =
                NinXmlParser.GetChildElements(e0, "unikId", TillatAntall.AkkuratEn);

            metadata.UniqueId = ParseIdentification(metadataUniqueIds[0]);

            var metadataPrograms =
                NinXmlParser.GetChildElements(e0, "program", TillatAntall.AkkuratEn);

            metadata.Program = metadataPrograms[0].Value;

            var metadataProjectNames =
                NinXmlParser.GetChildElements(e0, "prosjektnavn", TillatAntall.AkkuratEn);

            metadata.ProjectName = metadataProjectNames[0].Value;

            var metadataProjectDescriptions = NinXmlParser.GetChildElements(e0, "prosjektbeskrivelse",
                                                                            TillatAntall.MaksimaltEn);

            if (metadataProjectDescriptions.Count == 1)
            {
                metadata.ProjectDescription = metadataProjectDescriptions[0].Value;
            }

            var metadataPurposes = NinXmlParser.GetChildElements(e0, "formaal",
                                                                 TillatAntall.MaksimaltEn);

            if (metadataPurposes.Count == 1)
            {
                metadata.Purpose = metadataPurposes[0].Value;
            }

            var metadataContractors =
                NinXmlParser.GetChildElements(e0, "oppdragsgiver", TillatAntall.AkkuratEn);

            metadata.Contractor = NinXmlParser.ParseContact(metadataContractors[0]);

            var metadataOwners = NinXmlParser.GetChildElements(e0, "eier", TillatAntall.AkkuratEn);

            metadata.Owner = NinXmlParser.ParseContact(metadataOwners[0]);

            var metadataSurveyedFromDates = NinXmlParser.GetChildElements(e0, "kartlagtFraDato",
                                                                          TillatAntall.AkkuratEn);

            metadata.SurveyedFrom = Convert.ToDateTime(metadataSurveyedFromDates[0].Value);

            var metadataSurveyedToDates =
                NinXmlParser.GetChildElements(e0, "kartlagtTilDato", TillatAntall.AkkuratEn);

            metadata.SurveyedTo = Convert.ToDateTime(metadataSurveyedToDates[0].Value);

            var metadataSurveyScales = NinXmlParser.GetChildElements(e0, "kartleggingsMaalestokk",
                                                                     TillatAntall.AkkuratEn);

            metadata.SurveyScale = metadataSurveyScales[0].Value;

            var metadataResolutions = NinXmlParser.GetChildElements(e0, "opploesning",
                                                                    TillatAntall.MaksimaltEn);

            if (metadataResolutions.Count == 1)
            {
                metadata.Resolution = metadataResolutions[0].Value;
            }

            var metadataAreas =
                NinXmlParser.GetChildElements(e0, "dekningsOmraade", TillatAntall.AkkuratEn);
            int metadataAreaEspgCode;

            metadata.Area         = NinXmlParser.ParseGeometry(metadataAreas[0], out metadataAreaEspgCode);
            metadata.AreaEpsgCode = metadataAreaEspgCode;

            var metadataQualities =
                NinXmlParser.GetChildElements(e0, "kvalitet", TillatAntall.AkkuratEn);

            metadata.Quality = ParseQuality(metadataQualities[0]);

            var metadataDocuments = NinXmlParser.GetChildElements(e0, "dokumenter",
                                                                  TillatAntall.NullEllerFlere);

            foreach (var metadataDocument in metadataDocuments)
            {
                metadata.Documents.Add(NinXmlParser.ParseDocument(metadataDocument));
            }

            var metadataNatureAreas = NinXmlParser.GetChildElements(e0, "naturOmraader",
                                                                    TillatAntall.EnEllerFlere);

            foreach (var metadataNatureArea in metadataNatureAreas)
            {
                metadata.NatureAreas.AddRange(ParseNatureArea(metadataNatureArea));
            }

            var metadataVariableDefinitions = NinXmlParser.GetChildElements(e0, "variabelDefinisjoner",
                                                                            TillatAntall.EnEllerFlere);

            foreach (var metadataVariableDefinition in metadataVariableDefinitions)
            {
                metadata.VariabelDefinitions.Add(ParseVariableDefinition(metadataVariableDefinition));
            }

            return(metadata);
        }
        private static NatureArea ParseNatureArea2(XElement element)
        {
            var natureArea = new NatureArea();

            var natureAreaUniqueIds =
                NinXmlParser.GetChildElements(element, "unikId", TillatAntall.AkkuratEn);

            natureArea.UniqueId = ParseIdentification(natureAreaUniqueIds[0]);

            var natureAreaVersions =
                NinXmlParser.GetChildElements(element, "versjon", TillatAntall.AkkuratEn);

            natureArea.Version = natureAreaVersions[0].Value;

            var natureAreaNatureLevels =
                NinXmlParser.GetChildElements(element, "nivaa", TillatAntall.AkkuratEn);
            var xNaturnivå = natureAreaNatureLevels[0];

            switch (xNaturnivå.Value)
            {
            case "1":
                natureArea.Nivå = NatureLevel.Landskapstype;
                break;

            case "2":
                natureArea.Nivå = NatureLevel.Landskapsdel;
                break;

            case "3":
                natureArea.Nivå = NatureLevel.Naturkompleks;
                break;

            case "4":
                natureArea.Nivå = NatureLevel.Natursystem;
                break;

            case "5":
                natureArea.Nivå = NatureLevel.Naturkomponent;
                break;

            case "6":
                natureArea.Nivå = NatureLevel.Livsmedium;
                break;

            case "7":
                natureArea.Nivå = NatureLevel.KnowledgeArea;
                break;

            default:
                throw new DataDeliveryParseException("The element " + xNaturnivå.Name.LocalName +
                                                     " contains a unknown value.");
            }

            var natureAreaAreas =
                NinXmlParser.GetChildElements(element, "omraade", TillatAntall.AkkuratEn);
            int natureAreaEpsgCode;

            natureArea.Area         = NinXmlParser.ParseGeometry(natureAreaAreas[0], out natureAreaEpsgCode);
            natureArea.AreaEpsgCode = natureAreaEpsgCode;

            var natureAreaSurveyers = NinXmlParser.GetChildElements(element, "kartlegger",
                                                                    TillatAntall.MaksimaltEn);

            if (natureAreaSurveyers.Count == 1)
            {
                natureArea.Surveyer = NinXmlParser.ParseContact(natureAreaSurveyers[0]);
            }
            var natureAreaSurveyeds = NinXmlParser.GetChildElements(element, "kartlagtDato",
                                                                    TillatAntall.MaksimaltEn);

            if (natureAreaSurveyeds.Count == 1)
            {
                natureArea.Surveyed = Convert.ToDateTime(natureAreaSurveyeds[0].Value);
            }

            var natureAreaDescriptions = NinXmlParser.GetChildElements(element, "beskrivelse",
                                                                       TillatAntall.MaksimaltEn);

            if (natureAreaDescriptions.Count == 1)
            {
                natureArea.Description = natureAreaDescriptions[0].Value;
            }

            var natureAreaDocuments = NinXmlParser.GetChildElements(element, "dokumenter",
                                                                    TillatAntall.NullEllerFlere);

            foreach (var natureAreaDocument in natureAreaDocuments)
            {
                natureArea.Documents.Add(NinXmlParser.ParseDocument(natureAreaDocument));
            }

            var natureAreaParameters = NinXmlParser.GetChildElements(element, "parametre",
                                                                     TillatAntall.EnEllerFlere);

            foreach (var natureAreaParameter in natureAreaParameters)
            {
                natureArea.Parameters.Add(ParseParameter(natureAreaParameter));
            }

            return(natureArea);
        }