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);
        }