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);
        }
        private static void Validate(IEnumerable <NinVariabelDefinisjon> variableDefinitions, string natureLevelCode, NatureAreaType natureAreaType)
        {
            if (Naturkodetrær.Naturtyper.HentFraKode(natureAreaType.Code) == null)
            {
                throw new Exception("Ukjent Nin-kode: " + natureAreaType.Code);
            }

            if (!natureAreaType.Code.Substring(0, 2).Equals(natureLevelCode))
            {
                throw new Exception("Nature area type code " +
                                    natureAreaType.Code +
                                    " can not be a part of a nature area with nature level code " +
                                    natureLevelCode);
            }

            ValidateStandardVariableDefinition(variableDefinitions, natureAreaType);
        }