public static void CreateXML() { XmlDocument doc = new XmlDocument(); XmlDeclaration xmlDeclar = doc.CreateXmlDeclaration(version:"1.0",standalone:"yes",encoding:""); doc.PrependChild(xmlDeclar); XmlElement element = doc.CreateElement(name: "Users"); doc.AppendChild(element); XmlElement user = doc.CreateElement(name: "User"); user.SetAttribute(name: "ID", value: "1"); element.AppendChild(newChild: user); XmlElement userage = doc.CreateElement(name: "Age"); element.FirstChild.AppendChild(userage); XmlElement userName = doc.CreateElement(name: "Name"); userName.InnerText = "jambor"; element.FirstChild.PrependChild(newChild: userName); XmlElement userPhone= doc.CreateElement(name: "Phone"); XmlNode xmlNode = doc.DocumentElement; element.FirstChild.InsertBefore(newChild: userPhone, refChild: xmlNode.FirstChild.FirstChild); //XmlElement userAdd = doc.CreateElement(name: "Address"); //xmlNode.InsertAfter(newChild: userPhone, refChild: xmlNode.SelectNodes(xpath:"Name")[0]); doc.Save(filename: @"d:\user.xml"); }
public static XmlDocument XslExportTransform (XmlDocument doc) { XmlReader reader = Registry.GladeExportXsl.Transform (doc, null, (XmlResolver)null); doc = new XmlDocument (); doc.PreserveWhitespace = true; doc.Load (reader); XmlDocumentType doctype = doc.CreateDocumentType ("glade-interface", null, Glade20SystemId, null); doc.PrependChild (doctype); return doc; }
public static XmlDocument XslExportTransform (XmlDocument doc) { StringWriter sw = new StringWriter (); XmlWriter xw = XmlWriter.Create (sw); Registry.GladeExportXsl.Transform (doc, xw); XmlReader reader = XmlReader.Create (sw.ToString ()); doc = new XmlDocument (); doc.PreserveWhitespace = true; doc.Load (reader); XmlDocumentType doctype = doc.CreateDocumentType ("glade-interface", null, Glade20SystemId, null); doc.PrependChild (doctype); return doc; }
public XmlDocument Serialize(DataTable table) { if (table == null) { throw new ArgumentNullException("table"); } if (table.Columns.Count == 0) { throw new ArgumentOutOfRangeException("table", "DataTable specified contains no columns"); } var doc = new XmlDocument(); var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.PrependChild(xmlDeclaration); var root = doc.CreateElement(ColumnCollectionElementName); doc.AppendChild(root); foreach (var dataCol in table.Columns) { var col = (DataColumn)dataCol; var el = doc.CreateElement(ColumnElementName); el.SetAttribute(AttributeNames.Name, col.ColumnName); el.SetAttribute(AttributeNames.Type, col.DataType.FullName); el.SetAttribute(AttributeNames.Nullable, col.AllowDBNull.ToString(CultureInfo.InvariantCulture)); // MaxLength only relevant for strings if (col.DataType == typeof(string)) { el.SetAttribute(AttributeNames.Length, col.MaxLength.ToString(CultureInfo.InvariantCulture)); } root.AppendChild(el); } return doc; }
/// <summary> /// return a KML document /// </summary> /// <returns></returns> private XmlDocument getKmlDocument() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System KML interface"); doc.AppendChild(commentnode); XmlElement nodeKml = doc.CreateElement("kml"); nodeKml.SetAttribute("xmlns", "http://earth.google.com/kml/2.1"); doc.AppendChild(nodeKml); XmlElement elem = getXml(doc); nodeKml.AppendChild(elem); return (doc); }
/// <summary> /// Return a string containing the metadata XML based on the settings added to this instance. /// The resulting XML will be signed, if the AsymmetricAlgoritm property has been set. /// </summary> public string ToXml(Encoding enc) { XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml( Serialization.SerializeToXmlString(_entity)); // Add the correct encoding to the head element. if (doc.FirstChild is XmlDeclaration) ((XmlDeclaration) doc.FirstChild).Encoding = enc.WebName; else doc.PrependChild(doc.CreateXmlDeclaration("1.0", enc.WebName, null)); if (Sign) SignDocument(doc); return doc.OuterXml; }
// --------------------------------------------------------------------------------------------------- // Serialize // // Param assemblyPath: The full path + name of the assembly to be serialized // --------------------------------------------------------------------------------------------------- public static string Serialize(string assemblyPath) { Assembly assembly; // load the assembly try { //assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath); assembly = Assembly.LoadFrom(assemblyPath); } catch (Exception exc) { throw exc; } // extract the assembly name which is used as the XML parent node string sAssemblyName = assembly.FullName.Split(',')[0]; // create a new XML Document XmlDocument xmlDoc = new XmlDocument(); XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable); ns.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata"); ns.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); xmlDoc.PrependChild(xmlDec); // create parent node System.Xml.XmlElement elemRoot = xmlDoc.CreateElement(sAssemblyName); xmlDoc.AppendChild(elemRoot); // create longer static XML node using a string string sSchemaNode = "<xs:schema id=\"" + sAssemblyName + "\" xmlns=\"\" "; sSchemaNode += "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "; sSchemaNode += "xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">"; sSchemaNode += "<xs:element name=\"" + sAssemblyName + "\" msdata:IsDataSet=\"true\" msdata:Locale=\"en-US\">"; sSchemaNode += "<xs:complexType><xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">"; sSchemaNode += "</xs:choice></xs:complexType></xs:element></xs:schema>"; XmlDocumentFragment xmlDocFragment = xmlDoc.CreateDocumentFragment(); xmlDocFragment.InnerXml = sSchemaNode; elemRoot.AppendChild(xmlDocFragment); // select the "choice" node to include member types XmlNode choiceNode = xmlDoc.SelectSingleNode("/descendant::xs:choice[1]", ns); // list of all assembly types and relations Type[] assemblyTypes = assembly.GetTypes(); // remove duplicates assemblyTypes = assemblyTypes.GroupBy(x => x.Name).Select(y => y.First()).ToArray(); List<System.Xml.XmlElement> listAnnotations = new List<System.Xml.XmlElement>(); // loop through all classes in assembly foreach (Type type in assemblyTypes) { List<string> listMemberNames = new List<string>(); if (ContainsSpecialCharacters(type.Name)) continue; // create XML entries for the classes System.Xml.XmlElement typeElement = xmlDoc.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema"); typeElement.SetAttribute("name", type.Name); choiceNode.AppendChild(typeElement); System.Xml.XmlElement complexTypeElement = xmlDoc.CreateElement("xs", "complexType", "http://www.w3.org/2001/XMLSchema"); typeElement.AppendChild(complexTypeElement); System.Xml.XmlElement sequenceElement = xmlDoc.CreateElement("xs", "sequence", "http://www.w3.org/2001/XMLSchema"); complexTypeElement.AppendChild(sequenceElement); // loop through all properties and create XML nodes for return types foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (ContainsSpecialCharacters(property.Name) | listMemberNames.Contains(property.Name) | property.GetMethod == null) continue; if (assemblyTypes.Contains(property.GetMethod.ReturnType)) { System.Xml.XmlElement newAnnotationElement = CreateAnnotationElement(xmlDoc, type.Name, property.GetMethod.ReturnType.Name); if (newAnnotationElement != null) listAnnotations.Add(newAnnotationElement); } // add the member information as XML element sequenceElement.AppendChild(CreateMemberElement(xmlDoc, property.Name, property.GetMethod.ReturnType)); listMemberNames.Add(property.Name); } // loop through all methods and create XML nodes for return types foreach (MethodInfo method in type.GetMethods( BindingFlags.Public | BindingFlags.Instance) .Where(y => y.IsSpecialName == false)) { if (ContainsSpecialCharacters(method.Name) | listMemberNames.Contains(method.Name)) continue; if (assemblyTypes.Contains(method.ReturnType)) { System.Xml.XmlElement newAnnotationElement = CreateAnnotationElement(xmlDoc, type.Name, method.ReturnType.Name); if(newAnnotationElement != null) listAnnotations.Add(newAnnotationElement); } // add the member information as XML element sequenceElement.AppendChild(CreateMemberElement(xmlDoc, method.Name, method.ReturnType)); listMemberNames.Add(method.Name); } // write all relations as annotation tags foreach (System.Xml.XmlElement element in listAnnotations) { xmlDoc.SelectSingleNode(sAssemblyName).FirstChild.AppendChild(element); } // add an internal id to all classes for relations sequenceElement.AppendChild(CreateMemberElement(xmlDoc, "TXID_" + type.Name, typeof(Int32))); } return xmlDoc.InnerXml; }
private string ParseOptionsControls() { XmlDocument xDoc = new XmlDocument(); XmlElement options = xDoc.CreateElement("options"); xDoc.AppendChild(options); XmlElement settings = xDoc.CreateElement("settings"); options.AppendChild(settings); foreach (TreeNode tn in topLevel.Nodes) { if (tn.Tag != null && typeof(TableLayoutPanel).IsInstanceOfType(tn.Tag)) { XmlElement panel = xDoc.CreateElement("panel"); panel.SetAttribute("name", tn.Text); settings.AppendChild(panel); XmlElement controls = xDoc.CreateElement("controls"); panel.AppendChild(controls); foreach (Control c in ((TableLayoutPanel)tn.Tag).Controls) { if (!typeof(Label).IsInstanceOfType(c)) { int firstPos = c.ToString().IndexOf(','); int lastPos = c.ToString().Substring(0, firstPos).LastIndexOf('.'); string ctrlType = c.ToString().Substring(0, firstPos).Substring(lastPos + 1).Trim(); string ctrlValue = string.Empty; if (ctrlType.ToLower().Equals("textbox")) { ctrlValue = "Text: " + c.Text; } else { ctrlValue = c.ToString().Substring(firstPos + 1).Trim(); } XmlElement ctrl = xDoc.CreateElement("control"); ctrl.SetAttribute("name", c.Name); ctrl.SetAttribute("type", ctrlType); ctrl.InnerText = ctrlValue; controls.AppendChild(ctrl); } } } } XmlDeclaration declare = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); xDoc.PrependChild(declare); _values = xDoc.OuterXml; return _values; }
static public void XmlFromDataTable(System.Data.DataTable dt, string file, string senderID) { XmlDocument doc = new XmlDocument(); doc.PrependChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); XmlElement element = doc.CreateElement("Data"); element.SetAttribute("reportDate", DateTime.Now.ToString("MM/dd/yy HH:mm")); element.SetAttribute("senderID", senderID); doc.AppendChild(element); XmlElement devices = doc.CreateElement("Devices"); element.AppendChild(devices); foreach (DataRow r in dt.Rows) { XmlElement device = doc.CreateElement("Device"); // add each row's cell data... foreach (DataColumn c in dt.Columns) { insertElement(doc, device, c.ColumnName.Trim(), r[c.ColumnName].ToString().Trim()); } devices.AppendChild(device); } doc.Save(file); }
/// <summary> /// Inspect an XML document. /// </summary> /// <param name="doc">The XML document to inspect.</param> private void InspectDocument(XmlDocument doc) { // inspect the declaration if (XmlNodeType.XmlDeclaration == doc.FirstChild.NodeType) { XmlDeclaration declaration = (XmlDeclaration)doc.FirstChild; if (!String.Equals("utf-8", declaration.Encoding, StringComparison.OrdinalIgnoreCase)) { if (this.OnError(InspectorTestType.DeclarationEncodingWrong, declaration, "The XML declaration encoding is not properly set to 'utf-8'.")) { declaration.Encoding = "utf-8"; } } } else // missing declaration { if (this.OnError(InspectorTestType.DeclarationMissing, null, "This file is missing an XML declaration on the first line.")) { doc.PrependChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); } } // start inspecting the nodes at the document element this.InspectNode(doc.DocumentElement, 0); }
/// <summary> /// return an Xml document containing metagridBuffer /// </summary> /// <returns></returns> private XmlDocument getXmlDocument() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlElement nodeGeom = doc.CreateElement("OccupancyGrids"); doc.AppendChild(nodeGeom); nodeGeom.AppendChild( getXml(doc, nodeGeom)); return (doc); }
/// <summary> /// return an Xml document containing the status of the given list of devices /// </summary> /// <returns></returns> protected static XmlDocument GetDeviceStatus( ArrayList devs, string status_type) { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", XML_ENCODING, null); doc.PrependChild(dec); XmlElement statusreply = doc.CreateElement(status_type); doc.AppendChild(statusreply); for (int i = 0; i < devs.Count; i += 2) { string Id = (string)devs[i]; List<string> required_properties = (List<string>)devs[i + 1]; XmlElement status = GetDeviceStatus(Id, doc, statusreply, required_properties); if (status != null) statusreply.AppendChild(status); } //doc.Save("DeviceStatus.xml"); return (doc); }
private static XmlDocument ConstructXMLRequest(BaseRequest request, RequestTypeEnum requestType) { var xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml("<Request xmlns=\"urn:sbx:apis:SbxBaseComponents\"><RequesterCredentials><ApiUserToken>" + request.ApiUserToken + "</ApiUserToken><SbxUserToken>" + request.SbxUserToken + "</SbxUserToken></RequesterCredentials></Request>"); xmlDoc.PrependChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null)); var xmlRequestNode = xmlDoc.GetElementsByTagName("Request").Item(0); var xmlGetRequestTypeCallNode = xmlDoc.CreateElement(requestType.ToString()); xmlGetRequestTypeCallNode.SetAttribute("xmlns", "urn:sbx:apis:SbxBaseComponents"); xmlRequestNode.AppendChild(xmlGetRequestTypeCallNode); ConstructXMLCallNode(xmlDoc, request, requestType, xmlGetRequestTypeCallNode); } catch { throw new Exception("Error in Service."); } return xmlDoc; }
/// <summary> /// return an Xml document containing camera calibration parameters /// </summary> /// <param name="device_name"></param> /// <param name="part_number"></param> /// <param name="serial_number"></param> /// <param name="focal_length_pixels"></param> /// <param name="focal_length_mm"></param> /// <param name="baseline_mm"></param> /// <param name="fov_degrees"></param> /// <param name="image_width"></param> /// <param name="image_height"></param> /// <param name="lens_distortion_curve"></param> /// <param name="centre_of_distortion_x"></param> /// <param name="centre_of_distortion_y"></param> /// <param name="minimum_rms_error"></param> /// <param name="rotation"></param> /// <param name="scale"></param> /// <param name="offset_x"></param> /// <param name="offset_y"></param> /// <returns></returns> protected static XmlDocument getXmlDocument( string device_name, string part_number, string serial_number, float focal_length_pixels, float focal_length_mm, float baseline_mm, float fov_degrees, int image_width, int image_height, polynomial[] lens_distortion_curve, float[] centre_of_distortion_x, float[] centre_of_distortion_y, float[] minimum_rms_error, float rotation, float scale, float offset_x, float offset_y, bool disable_rectification, bool disable_radial_correction, bool flip_left_image, bool flip_right_image) { //usage.Update("Get xml document, BaseVisionStereo, GetXmlDocument"); // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System"); doc.AppendChild(commentnode); XmlElement nodeCalibration = doc.CreateElement("Sentience"); doc.AppendChild(nodeCalibration); XmlElement elem = getXml(doc, nodeCalibration, device_name, part_number, serial_number, focal_length_pixels, focal_length_mm, baseline_mm, fov_degrees, image_width, image_height, lens_distortion_curve, centre_of_distortion_x, centre_of_distortion_y, minimum_rms_error, rotation, scale, offset_x, offset_y, disable_rectification, disable_radial_correction, flip_left_image, flip_right_image); doc.DocumentElement.AppendChild(elem); return (doc); }
/// <summary> /// <c>CreateXMLFileForStoringUserOptions</c> /// creates xml file to store UserOptions either to select AutoDelete Emails after uploading or not /// </summary> /// <param name="xLogOptions"></param> /// <returns></returns> public static bool CreateXMLFileForStoringUserOptions(XMLLogOptions xLogOptions) { try { //, Folder name, site url, authentication mode and credentials. XmlDocument xmlDoc = new XmlDocument(); XmlElement elemRoot = null, elem = null; XmlNode root = null; bool isNewXMlFile = true; UserLogManagerUtility.CheckItopiaDirectoryExits(); //Check file is existed or not if (System.IO.File.Exists(UserLogManagerUtility.XMLOptionsFilePath) == true) { //Save the details in Xml file xmlDoc.Load(UserLogManagerUtility.XMLOptionsFilePath); xmlDoc.RemoveAll(); } XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); xmlDoc.PrependChild(xmlDec); XmlElement docRoot = xmlDoc.CreateElement("UserOptionsLog"); xmlDoc.AppendChild(docRoot); //Create root node elemRoot = xmlDoc.CreateElement("Options"); docRoot.AppendChild(elemRoot); elem = xmlDoc.CreateElement("AutoDeleteEmails"); elem.InnerText = Convert.ToString(xLogOptions.AutoDeleteEmails); elemRoot.AppendChild(elem); if (isNewXMlFile == false) { //XML file already existed add the node to xml file root.InsertBefore(elemRoot, root.FirstChild); } //Save xml file xmlDoc.Save(UserLogManagerUtility.XMLOptionsFilePath); return true; } catch (Exception ex) { throw ex; } return false; }
/// <summary> /// <c>CreateXMLFileForStoringUserCredentials</c> /// Method to save user credentionals /// </summary> /// <param name="xLogproperties"></param> /// <returns></returns> public static bool CreateXMLFileForStoringUserCredentials(XMLLogProperties xLogproperties) { try { //, Folder name, site url, authentication mode and credentials. xLogproperties.UserName = EncodingAndDecoding.Base64Encode(xLogproperties.UserName); xLogproperties.Password = EncodingAndDecoding.Base64Encode(xLogproperties.Password); XmlDocument xmlDoc = new XmlDocument(); XmlElement elemRoot = null, elem = null; XmlNode root = null; bool isNewXMlFile = true; UserLogManagerUtility.CheckItopiaDirectoryExits(); //Check file is existed or not if (System.IO.File.Exists(UserLogManagerUtility.XMLFilePath) == true) { //Save the details in Xml file xmlDoc.Load(UserLogManagerUtility.XMLFilePath); //Get the root Elemet root = xmlDoc.DocumentElement; elemRoot = xmlDoc.CreateElement("Folder"); isNewXMlFile = false; } else { XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); xmlDoc.PrependChild(xmlDec); XmlElement docRoot = xmlDoc.CreateElement("UserCredentialsLog"); xmlDoc.AppendChild(docRoot); //Create root node elemRoot = xmlDoc.CreateElement("Folder"); docRoot.AppendChild(elemRoot); } elem = xmlDoc.CreateElement("UserName"); elem.InnerText = xLogproperties.UserName; elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("Password"); elem.InnerText = xLogproperties.Password; elemRoot.AppendChild(elem); //string strFolderName,string strSiteURL,string strAuthenticationType) elem = xmlDoc.CreateElement("DisplayName"); elem.InnerText = xLogproperties.DisplayFolderName; elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("DocLibName"); elem.InnerText = xLogproperties.DocumentLibraryName; elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("URL"); elem.InnerText = xLogproperties.SiteURL; elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("AuthenticationType"); if (xLogproperties.FolderAuthenticationType == AuthenticationType.Domain) { elem.InnerText = "Domain Credentials"; } else { elem.InnerText = "Manually Specified"; } elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("Status"); if (xLogproperties.UsersStatus == UserStatus.Active) { elem.InnerText = "Active"; } else { elem.InnerText = "Removed"; } elemRoot.AppendChild(elem); //this will used to check the folder already existed or not elem = xmlDoc.CreateElement("FolderNameToCompare"); elem.InnerText = xLogproperties.DisplayFolderName.ToUpper(); elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("OutlookLocation"); xLogproperties.OutlookFolderLocation = xLogproperties.OutlookFolderLocation.Replace("\\\\", ""); elem.InnerText = xLogproperties.OutlookFolderLocation; elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("DateAdded"); elem.InnerText = System.DateTime.Now.ToString(); elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("LastUpload"); elem.InnerText = System.DateTime.Now.ToString(); elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("URLType"); elem.InnerText = xLogproperties.DroppedURLType; elemRoot.AppendChild(elem); elem = xmlDoc.CreateElement("SPSiteVersion"); elem.InnerText = xLogproperties.SPSiteVersion; elemRoot.AppendChild(elem); if (isNewXMlFile == false) { //XML file already existed add the node to xml file root.InsertBefore(elemRoot, root.FirstChild); } //Save xml file xmlDoc.Save(UserLogManagerUtility.XMLFilePath); return true; } catch (Exception ex) { throw ex; } return false; }
/// <summary> /// return an Xml document used as a reply to the client after an update of parameters has been received and carried out /// </summary> /// <returns>reply xml document</returns> protected static XmlDocument GetDeviceUpdateReply() { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", XML_ENCODING, null); doc.PrependChild(dec); XmlElement statusreply = doc.CreateElement(STATUS_REPLY); doc.AppendChild(statusreply); //doc.Save("DeviceUpdateReply.xml"); return (doc); }
/// <summary> /// return an Xml document containing sensor models /// </summary> /// <returns></returns> private XmlDocument getXmlDocumentSensorModels() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlElement nodeSensors = doc.CreateElement("Sensors"); doc.AppendChild(nodeSensors); nodeSensors.AppendChild( getXmlSensorModels(doc, nodeSensors)); return (doc); }
/// <summary> /// return an Xml document containing camera calibration parameters /// </summary> /// <returns></returns> private XmlDocument getXmlDocument() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System"); doc.AppendChild(commentnode); XmlElement nodeCalibration = doc.CreateElement("Sentience"); doc.AppendChild(nodeCalibration); xml.AddComment(doc, nodeCalibration, "Calibration apparatus setup parameters"); XmlElement nodeCalibSetup = doc.CreateElement("CalibrationSetup"); nodeCalibration.AppendChild(nodeCalibSetup); xml.AddComment(doc, nodeCalibSetup, "Horizontal field of view of the camera in degrees"); xml.AddTextElement(doc, nodeCalibSetup, "FieldOfViewDegrees", txtFOV.Text); xml.AddComment(doc, nodeCalibSetup, "Position of the centre spot relative to the centre of the calibration pattern"); xml.AddComment(doc, nodeCalibSetup, "0 - North West"); xml.AddComment(doc, nodeCalibSetup, "1 - North East"); xml.AddComment(doc, nodeCalibSetup, "2 - South East"); xml.AddComment(doc, nodeCalibSetup, "3 - South West"); xml.AddTextElement(doc, nodeCalibSetup, "CentreSpotPosition", Convert.ToString(cmbCentreSpotPosition.SelectedIndex)); xml.AddComment(doc, nodeCalibSetup, "Distance from the camera to the centre of the calibration pattern along the ground in mm"); xml.AddTextElement(doc, nodeCalibSetup, "DistToCentreMillimetres", txtDistToCentre.Text); xml.AddComment(doc, nodeCalibSetup, "height of the camera above the ground in mm"); xml.AddTextElement(doc, nodeCalibSetup, "CameraHeightMillimetres", txtCameraHeight.Text); xml.AddComment(doc, nodeCalibSetup, "Calibration pattern spacing in mm"); xml.AddTextElement(doc, nodeCalibSetup, "PatternSpacingMillimetres", txtPatternSpacing.Text); xml.AddComment(doc, nodeCalibSetup, "Baseline Distance mm"); xml.AddTextElement(doc, nodeCalibSetup, "BaselineMillimetres", txtBaseline.Text); if (cam.leftcam.ROI != null) { xml.AddComment(doc, nodeCalibSetup, "Region of interest in the left image"); xml.AddTextElement(doc, nodeCalibSetup, "LeftROI", Convert.ToString(cam.leftcam.ROI.tx) + "," + Convert.ToString(cam.leftcam.ROI.ty) + "," + Convert.ToString(cam.leftcam.ROI.bx) + "," + Convert.ToString(cam.leftcam.ROI.by)); } if (cam.rightcam.ROI != null) { xml.AddComment(doc, nodeCalibSetup, "Region of interest in the right image"); xml.AddTextElement(doc, nodeCalibSetup, "RightROI", Convert.ToString(cam.rightcam.ROI.tx) + "," + Convert.ToString(cam.rightcam.ROI.ty) + "," + Convert.ToString(cam.rightcam.ROI.bx) + "," + Convert.ToString(cam.rightcam.ROI.by)); } return (doc); }
/// <summary> /// return an Xml document containing camera calibration parameters /// </summary> /// <returns></returns> private XmlDocument getXmlDocument() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System"); doc.AppendChild(commentnode); XmlElement nodeCalibration = doc.CreateElement("Sentience"); doc.AppendChild(nodeCalibration); xml.AddComment(doc, nodeCalibration, "Camera calibration data"); XmlElement elem = getXml(doc); doc.DocumentElement.AppendChild(elem); return (doc); }
/// <summary> /// returns the status of all devices as a string /// </summary> /// <param name="Devices"></param> /// <param name="usage"></param> /// <returns></returns> protected static string getDeviceStatusAll() { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", XML_ENCODING, null); doc.PrependChild(dec); XmlElement bridgeware = doc.CreateElement(STATUS_REPLY); doc.AppendChild(bridgeware); XmlElement status = GetDeviceStatusAll(doc, bridgeware); bridgeware.AppendChild(status); string statusStr = doc.InnerXml; //doc.Save("StatusAll.xml"); return (statusStr); }
/// <summary> /// Return a string containing the metadata XML based on the settings added to this instance. /// The resulting XML will be signed, if the AsymmetricAlgorithm property has been set. /// </summary> /// <param name="encoding">The encoding.</param> /// <returns>The XML.</returns> public string ToXml(Encoding encoding) { var doc = new XmlDocument { PreserveWhitespace = true }; doc.LoadXml(Serialization.SerializeToXmlString(Entity)); // Add the correct encoding to the head element. if (doc.FirstChild is XmlDeclaration) { ((XmlDeclaration)doc.FirstChild).Encoding = encoding.WebName; } else { doc.PrependChild(doc.CreateXmlDeclaration("1.0", encoding.WebName, null)); } if (Sign) { SignDocument(doc); } return doc.OuterXml; }
XmlDocument createXmlConfig() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<config></config>"); doc.PrependChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "")); //XmlNode config = doc.CreateElement("config"); //doc.AppendChild(config); XmlNode config = doc.GetElementsByTagName("config")[0]; XmlElement AVR = doc.CreateElement("AVR"); config.AppendChild(AVR); XmlElement COM = doc.CreateElement("COM"); AVR.AppendChild(COM); XmlElement baud = doc.CreateElement("Baudrate"); AVR.AppendChild(baud); XmlElement databits = doc.CreateElement("Databits"); AVR.AppendChild(databits); XmlElement stopbit = doc.CreateElement("Stopbits"); AVR.AppendChild(stopbit); XmlElement parity = doc.CreateElement("Parity"); AVR.AppendChild(parity); XmlElement handshake = doc.CreateElement("Handshake"); AVR.AppendChild(handshake); XmlElement arduitoBootloader = doc.CreateElement("Arduino_Bootloader"); AVR.AppendChild(arduitoBootloader); XmlElement bootloaderCOM = doc.CreateElement("Arduino_Bootloader_COM"); AVR.AppendChild(bootloaderCOM); XmlElement lang = doc.CreateElement("Language"); config.AppendChild(lang); XmlElement dome = doc.CreateElement("Dome"); config.AppendChild(dome); XmlElement accel = doc.CreateElement("accel_time"); dome.AppendChild(accel); XmlElement speed = doc.CreateElement("angular_speed_rpm"); dome.AppendChild(speed); XmlElement thsld = doc.CreateElement("Threshold"); dome.AppendChild(thsld); XmlElement encoder = doc.CreateElement("Encoder"); config.AppendChild(encoder); XmlElement type = doc.CreateElement("type"); encoder.AppendChild(type); XmlElement res = doc.CreateElement("resolution"); encoder.AppendChild(res); XmlElement gearRatio = doc.CreateElement("gear_ratio"); encoder.AppendChild(gearRatio); XmlElement pos = doc.CreateElement("LastPosition"); encoder.AppendChild(pos); COM.InnerText = AVR_COM_Name; baud.InnerText = AVR_COM_Baudrate.ToString(); databits.InnerText = AVR_COM_Databits.ToString(); stopbit.InnerText = AVR_COM_Stopbits.ToString(); parity.InnerText = AVR_COM_Parity.ToString(); handshake.InnerText = AVR_COM_Handshake.ToString(); arduitoBootloader.InnerText = isArduinoBootloader.ToString(); bootloaderCOM.InnerText = AVRBootLoader_COM; lang.InnerText = language; type.InnerText = "Incremental"; res.InnerText = this.EncoderRes.Value.ToString(); gearRatio.InnerText = this.GearRatio.Value.ToString(); pos.InnerText = _dome.Azimuth.ToString(); accel.InnerText = MotorAccelleration.Value.ToString(); speed.InnerText = MotorSpeed.Value.ToString(); thsld.InnerText = this.Threshold.Value.ToString(); return doc; }
/// <summary> /// Inspect an XML document. /// </summary> /// <param name="doc">The XML document to inspect.</param> private void InspectDocument(XmlDocument doc) { // inspect the declaration if (XmlNodeType.XmlDeclaration == doc.FirstChild.NodeType) { XmlDeclaration declaration = (XmlDeclaration)doc.FirstChild; if ("UTF-8" != declaration.Encoding) { this.OnError(InspectorTestType.DeclarationEncodingWrong, declaration, "The XML declaration encoding is not properly set to 'UTF-8'."); declaration.Encoding = "UTF-8"; } } else // missing declaration { this.OnError(InspectorTestType.DeclarationMissing, null, "This file is missing an XML declaration on the first line."); doc.PrependChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null)); } // start inspecting the nodes at the document element this.InspectNode(doc.DocumentElement, 0); }
/// <summary> /// return an Xml document containing camera calibration parameters /// </summary> /// <returns></returns> private XmlDocument getXmlDocument() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System"); doc.AppendChild(commentnode); XmlElement nodeSentience = doc.CreateElement("Sentience"); doc.AppendChild(nodeSentience); nodeSentience.AppendChild(getXml(doc, nodeSentience)); return (doc); }
/// <summary> /// return an Xml document containing camera calibration parameters /// </summary> /// <param name="device_name"></param> /// <param name="focal_length_pixels"></param> /// <param name="baseline_mm"></param> /// <param name="fov_degrees"></param> /// <param name="image_width"></param> /// <param name="image_height"></param> /// <param name="lens_distortion_curve"></param> /// <param name="centre_of_distortion_x"></param> /// <param name="centre_of_distortion_y"></param> /// <param name="rotation"></param> /// <param name="scale"></param> /// <param name="lens_distortion_image_filename"></param> /// <param name="curve_fit_image_filename"></param> /// <param name="offset_x"></param> /// <param name="offset_y"></param> /// <param name="pan_curve"></param> /// <param name="pan_offset_x"></param> /// <param name="pan_offset_y"></param> /// <param name="tilt_curve"></param> /// <param name="tilt_offset_x"></param> /// <param name="tilt_offset_y"></param> /// <returns></returns> private static XmlDocument getXmlDocument( string device_name, float focal_length_pixels, float baseline_mm, float fov_degrees, int image_width, int image_height, polynomial[] lens_distortion_curve, double[] centre_of_distortion_x, double[] centre_of_distortion_y, double[] rotation, double[] scale, string[] lens_distortion_image_filename, string[] curve_fit_image_filename, float offset_x, float offset_y, polynomial pan_curve, float pan_offset_x, float pan_offset_y, polynomial tilt_curve, float tilt_offset_x, float tilt_offset_y) { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System"); doc.AppendChild(commentnode); XmlElement nodeCalibration = doc.CreateElement("Sentience"); doc.AppendChild(nodeCalibration); xml.AddComment(doc, nodeCalibration, "Sentience"); XmlElement elem = getXml(doc, nodeCalibration, device_name, focal_length_pixels, baseline_mm, fov_degrees, image_width, image_height, lens_distortion_curve, centre_of_distortion_x, centre_of_distortion_y, rotation, scale, lens_distortion_image_filename, curve_fit_image_filename, offset_x, offset_y, pan_curve, pan_offset_x, pan_offset_y, tilt_curve, tilt_offset_x, tilt_offset_y); doc.DocumentElement.AppendChild(elem); return (doc); }
public XmlDocument getXML() { // Create the document. XmlDocument doc = new XmlDocument(); // Insert the xml processing instruction and the root node XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); doc.PrependChild(dec); XmlElement nodeSociety = doc.CreateElement("Society"); doc.AppendChild(nodeSociety); if (locations.Count > 0) { XmlElement nodeGeography = doc.CreateElement("Geography"); nodeSociety.AppendChild(nodeGeography); // locations for (int i = 0; i < locations.Count; i++) { location loc = (location)locations[i]; XmlElement elem = loc.getXML(doc); nodeGeography.AppendChild(elem); } } if (personalities.Count > 0) { XmlElement nodePopulation = doc.CreateElement("Population"); nodeSociety.AppendChild(nodePopulation); // people for (int i = 0; i < personalities.Count; i++) { personality p = (personality)personalities[i]; XmlElement elem = p.getXML(doc); nodePopulation.AppendChild(elem); } } if (events.Count > 0) { XmlElement nodeEvents = doc.CreateElement("Events"); nodeSociety.AppendChild(nodeEvents); // events for (int i = 0; i < events.Count; i++) { societyevent e = (societyevent)events[i]; XmlElement elem = e.getXML(doc); nodeEvents.AppendChild(elem); } } return (doc); }