private XsdNs.InsertObservationType ToXmlProxy() { var proxy = new XsdNs.InsertObservationType() { // Assigning mandatory attributes specified in the SWES standard. // These values are after the SOS specification. service = "SOS", version = "2.0.0", observation = new XsdNs.InsertObservationTypeObservation[Observations.Count] }; // Populating offerings. There must be at least one value. // Therefore, adding an empty value if none have been specified. // Offerings are of the XML type "anyUri", which allows even an empty value. if (Offering.Count == 0) { Offering.Add(""); } proxy.offering = new string[Offering.Count]; for (int a = 0; a < Offering.Count; ++a) { proxy.offering[a] = Offering[a]; } // XML Schema requires at least one observation if (Observations.Count < 1) { throw new ArgumentException("InsertObservationRequest must contain at least one observation"); } // Populating observation data to proxy var index = 0; const string idPrefix = "InsertObsReq_i"; foreach (var obs in Observations) { // To have unique IDs in the XML doc: var idPrefixForThis = BuildIdPrefix(idPrefix, index + 1); // Creating an observation proxy proxy.observation[index] = new XsdNs.InsertObservationTypeObservation { OM_Observation = obs.ToXmlProxy(idPrefixForThis) }; ++index; } return(proxy); }
private void ReadFieldValuesFromXmlDoc(XsdNs.InsertObservationType proxy) { // Reading offerings if (proxy.offering != null) { foreach (string s in proxy.offering) { Offering.Add(s); } } // Reading observations if (proxy.observation != null && proxy.observation.Length > 0) { foreach (var obsRaw in proxy.observation) { var observation = new Observation(obsRaw.OM_Observation); Observations.Add(observation); } } }