public XDocument ToXml(Dataleveranse dataleveranse) { var xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "no")); var dataDeliveryElement = new NinXElement("DataLeveranse", "", new XAttribute(XNamespace.Xmlns + "gml", gmlNs), new XAttribute(XNamespace.Xmlns + "nin", Config.Settings.Namespace.Nin), new NinXElement("navn", "dataDelivery.Name", dataleveranse.Name), new NinXElement("leveranseDato", "dataDelivery.DeliveryDate", dataleveranse.DeliveryDate), XmlSkriver.ContactElement("operatoer", dataleveranse.Operator), new NinXElement("grunnForEndring", "dataDelivery.ReasonForChange", dataleveranse.ReasonForChange), new NinXElement("beskrivelse", "dataDelivery.Description", dataleveranse.Description), AddMetadataElements(new Collection <Metadata> { dataleveranse.Metadata }) ); dataDeliveryElement.Print(""); xDocument.Add(dataDeliveryElement); var emptyElements = from element in xDocument.Descendants() where element.IsEmpty select element; while (emptyElements.Any()) { emptyElements.Remove(); } return(xDocument); }
public XDocument ToXml(GridLayer gridLayer) { var xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "no")); XElement gridNetElement = new NinXElement("RuteNettKart", "", new XAttribute(XNamespace.Xmlns + "nin", Config.Settings.Namespace.Nin), new XAttribute(XNamespace.Xmlns + "gml", gmlNs), new NinXElement("navn", "gridLayer.Name", gridLayer.Name), new NinXElement("beskrivelse", "gridLayer.Description", gridLayer.Description), new NinXElement("kode", "AddCodeElement('Kode', gridLayer.Code)", AddCodeElement("Kode", gridLayer.Code)), XmlSkriver.ContactElement("eier", gridLayer.Owner), new NinXElement("etablertDato", "gridLayer.Established", gridLayer.Established), new NinXElement("ruteNett", "(int)gridLayer.Type", (int)gridLayer.Type), AddMapElements(gridLayer.Cells, gridLayer.Code != null ? gridLayer.Code.Value : string.Empty) ); xDocument.Add(gridNetElement); var emptyElements = from element in xDocument.Descendants() where element.IsEmpty select element; while (emptyElements.Any()) { emptyElements.Remove(); } return(xDocument); }
private IEnumerable <XElement> AddMetadataElements(IEnumerable <Metadata> metadatas) { return(metadatas.Select( m => new NinXElement("metadata", "", new NinXElement("Metadata", "", new XAttribute(gmlNs + "id", "METADATA_" + m.UniqueId.LocalId), XmlSkriver.IdentificationElement("unikId", m.UniqueId), new NinXElement("program", "m.Program", m.Program), new NinXElement("prosjektnavn", "m.ProjectName", m.ProjectName), new NinXElement("prosjektbeskrivelse", "m.ProjectDescription", m.ProjectDescription), new NinXElement("formaal", "m.Purpose", m.Purpose), XmlSkriver.ContactElement("oppdragsgiver", m.Contractor), XmlSkriver.ContactElement("eier", m.Owner), new NinXElement("kartlagtFraDato", "m.SurveyedFrom", m.SurveyedFrom), new NinXElement("kartlagtTilDato", "m.SurveyedTo", m.SurveyedTo), new NinXElement("kartleggingsMaalestokk", "m.SurveyScale", m.SurveyScale), new NinXElement("opploesning", "m.Resolution", m.Resolution), XmlSkriver.AreaElement("dekningsOmraade", m.Area, m.UniqueId.LocalId), AddQualityElement("kvalitet", m.Quality), XmlSkriver.DocumentElements(m.Documents), xmlSkriver.NatureAreaElements(m.NatureAreas), AddVariableDefinitions(m.VariabelDefinitions) ) ) )); }
public XmlConverter() { xmlSkriver = new XmlSkriver(); gmlNs = Config.Settings.Namespace.Gml; }