private string ToXmlStringSummary() { Type t = this.GetType(); PFXmlDocument xmldoc = new PFXmlDocument(t.Name); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "Name", this.Name); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "FullName", this.FullName); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumBytesInDirectory", this.NumBytesInDirectory.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumFilesInDirectory", this.NumFilesInDirectory.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumSubdirectoriesInDirectory", this.NumSubdirectoriesInDirectory.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumBytesInDirectoryTree", this.NumBytesInDirectoryTree.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "TotalNumFilesInDirectoryTree", this.TotalNumFilesInDirectoryTree.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "TotalNumSubdirectoriesInDirectoryTree", this.TotalNumSubdirectoriesInDirectoryTree.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumErrors", this.NumErrors.ToString("#,##0")); xmldoc.AddNewElement(xmldoc.DocumentRootNode, "ErrorMessages", this.ErrorMessages); return(xmldoc.OuterXml); }
/// <summary> /// Returns a string containing the contents of the object in XML format. /// </summary> /// <returns>String value in xml format.</returns> /// ///<remarks>XML Serialization is used for the transformation.</remarks> public string ToXmlString() { Type t = this.GetType(); PFXmlDocument xmldoc = new PFXmlDocument(t.Name); PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); int inx = 0; int maxInx = props.Length - 1; for (inx = 0; inx <= maxInx; inx++) { PropertyInfo prop = props[inx]; object val = prop.GetValue(this, null); xmldoc.AddNewElement(xmldoc.DocumentRootNode, prop.Name, val.ToString()); } return(xmldoc.OuterXml); //XmlSerializer ser = new XmlSerializer(typeof(PFFileEx)); //StringWriter tex = new StringWriter(); //ser.Serialize(tex, this); //return tex.ToString(); }
public static void RunTest_Memory(string _filename, string _rootNode) { _xmlDoc = new PFXmlDocument(_rootNode); XmlElement xmlElement; XmlElement saveXmlElement; xmlElement = _xmlDoc.AddNewElement(_xmlDoc.DocumentRootNode, "ProcessingDate", DateTime.Now.ToString()); saveXmlElement = _xmlDoc.AddNewElement(_xmlDoc.DocumentRootNode, "IsEnabled", "True"); xmlElement = _xmlDoc.AddNewElement(saveXmlElement, "node1", "text1"); xmlElement = _xmlDoc.AddNewElement(saveXmlElement, "node2", "text2"); _xmlDoc.AddNewAttribute(xmlElement, "attr1", "val1"); xmlElement = _xmlDoc.AddNewElement(saveXmlElement, "node3", "text3"); _xmlDoc.AddNewAttribute(xmlElement, "attr3a", "val3a"); _xmlDoc.AddNewAttribute(xmlElement, "attr3b", "val3b"); xmlElement = _xmlDoc.AddNewElement(_xmlDoc.DocumentRootNode, "FormBackground", "Red"); _xmlDoc.SaveToFile(_filename); PFXmlDocument xmlDoc2 = new PFXmlDocument(); xmlDoc2.LoadFromFile(_filename); Program._messageLog.WriteLine(xmlDoc2.OuterXml); Program._messageLog.WriteLine("\r\n" + xmlDoc2.InnerText); Program._messageLog.WriteLine("\r\n" + xmlDoc2.InnerXml); }
private string ToXmlStringDetail() { Type t = this.GetType(); PFXmlDocument xmldoc = new PFXmlDocument(t.Name); PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); int inx = 0; int maxInx = props.Length - 1; for (inx = 0; inx <= maxInx; inx++) { PropertyInfo prop = props[inx]; object val = prop.GetValue(this, null); xmldoc.AddNewElement(xmldoc.DocumentRootNode, prop.Name, val.ToString()); } return(xmldoc.OuterXml); }
public static void AddNodes(MainForm frm) { bool err = false; XmlElement xmlElement; StringBuilder nodePath = new StringBuilder(); Program._messageLog.Clear(); if (frm.txtNodePath.Text.Length == 0) { Program._messageLog.WriteLine("Node path must be specified."); err = true; } if (err) { return; } if (frm.txtNodePath.Text.Length > 0) { if (frm.txtNodeTag.Text.Length > 0) { nodePath.Length = 0; nodePath.Append(frm.txtRootNode.Text); nodePath.Append("/"); nodePath.Append(frm.txtNodePath.Text); try { xmlElement = _xmlDoc.FindElement(nodePath.ToString()); if (xmlElement == null) { xmlElement = _xmlDoc.FindElement(frm.txtRootNode.Text); _xmlDoc.AddNewElement(xmlElement, frm.txtNodePath.Text, string.Empty); xmlElement = _xmlDoc.FindElement(nodePath.ToString()); } _xmlDoc.AddNewElement((XmlNode)xmlElement, frm.txtNodeTag.Text, frm.txtNodeInnerText.Text); } catch (Exception ex) { _msg.Length = 0; _msg.Append("Attempt to add element failed.\n"); _msg.Append("Node tag: "); _msg.Append(frm.txtNodeTag.Text); _msg.Append("\n\n"); _msg.Append(AppMessages.FormatErrorMessage(ex)); AppMessages.DisplayErrorMessage(_msg.ToString()); } _xmlDoc.SaveToFile(frm.txtFilename.Text); } if (frm.txtAttribute.Text.Length > 0) { nodePath.Length = 0; nodePath.Append(frm.txtRootNode.Text); nodePath.Append("/"); nodePath.Append(frm.txtNodePath.Text); if (frm.txtNodeTag.Text.Length > 0) { nodePath.Append("/"); nodePath.Append(frm.txtNodeTag.Text); } try { xmlElement = _xmlDoc.FindElement(nodePath.ToString()); _xmlDoc.AddNewAttribute(xmlElement, frm.txtAttribute.Text, frm.txtAttributeValue.Text); } catch (Exception ex) { _msg.Length = 0; _msg.Append("Attempt to add attribute failed.\n"); _msg.Append("Node tag: "); _msg.Append(frm.txtNodeTag.Text); _msg.Append("\n\n"); _msg.Append(AppMessages.FormatErrorMessage(ex)); AppMessages.DisplayErrorMessage(_msg.ToString()); } _xmlDoc.SaveToFile(frm.txtFilename.Text); } } OutputContentsOfFile(frm.txtFilename.Text); }