/// <summary> /// Creates XML elements from the data of the system. /// </summary> /// <param name="xmlWriter">Object with the XML message to add new information and return to client side</param> /// <param name="val">Value to be puted inside the XML message</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> /// <param name="xmlElement">Element of the XML that is checked</param> public static void ON2XML(XmlWriter xmlWriter, ONReal val, double dtdVersion, string xmlElement) { if (val == null) { if (xmlElement == ONXml.XMLTAG_V) { xmlWriter.WriteElementString(xmlElement, ""); } else { xmlWriter.WriteElementString(ONXml.XMLTAG_NULL, null); } } else { if (dtdVersion < 2.0) // Apply the locale format { xmlWriter.WriteElementString(xmlElement, val.TypedValue.ToString("0.##############")); } else { xmlWriter.WriteStartElement(xmlElement); if (xmlElement == ONXml.XMLTAG_OIDFIELD && dtdVersion > 2.0) { xmlWriter.WriteAttributeString("Type", "real"); } string lValue = Pack(val); xmlWriter.WriteString(lValue); xmlWriter.WriteEndElement(); } } }
/// <summary> /// Checks the format of the data previously to be included in the XML message /// </summary> /// <param name="val">Contains the data to be checked</param> public static string Pack(ONReal val) { if (val.TypedValue == 0) { return("0"); } else { //Convert the value in a string with scientific format. string lValue = val.TypedValue.ToString("0.0#############E-0").Replace(",", "."); return(lValue); } }