WriteComment() public method

public WriteComment ( string text ) : void
text string
return void
Beispiel #1
0
        /// <summary>
        /// 写入配置参数数据
        /// </summary>
        /// <param name="Path"></param>
        public void WriterXml(string Path)
        {


            try
            {
                // 创建XmlTextWriter类的实例对象
                XmlTextWriter textWriter = new XmlTextWriter(Path, null);
                textWriter.Formatting = Formatting.Indented;

                // 开始写过程,调用WriteStartDocument方法
                textWriter.WriteStartDocument();

                // 写入说明
                textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
                textWriter.WriteComment("w3sky.xml in root dir");

                //创建一个节点
                textWriter.WriteStartElement("Administrator");
                textWriter.WriteElementString("Name", "formble");
                textWriter.WriteElementString("site", "w3sky.com");
                textWriter.WriteEndElement();

                // 写文档结束,调用WriteEndDocument方法
                textWriter.WriteEndDocument();

                // 关闭textWriter
                textWriter.Close();

            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// 写入配置参数数据
        /// </summary>
        /// <param name="Path"></param>
        public void WriterXml(string Path)
        {
            try
            {
                // 创建XmlTextWriter类的实例对象
                XmlTextWriter textWriter = new XmlTextWriter(Path, null);
                textWriter.Formatting = Formatting.Indented;

                // 开始写过程,调用WriteStartDocument方法
                textWriter.WriteStartDocument();

                // 写入说明
                textWriter.WriteComment("=====系统数据库定義=====");

                //创建一个节点
                textWriter.WriteStartElement("Parameter");
                textWriter.WriteElementString("Server", "192.168.1.16");
                textWriter.WriteElementString("Database", "RFIDDeliveryDB");
                textWriter.WriteElementString("User", "SA");
                textWriter.WriteElementString("Password", "");

                textWriter.WriteComment("=====数据库类型=====");
                textWriter.WriteElementString("DataSourceType", "1");

                textWriter.WriteComment("=====日志文件=====");
                textWriter.WriteElementString("LogFileName", "LogFiles");

                textWriter.WriteComment("=====日志文件=====");
                textWriter.WriteElementString("LogThreadFileName", "LogThreadFiles");

                textWriter.WriteComment("=====手持设备参数=====");
                textWriter.WriteElementString("Baud", "5");
                textWriter.WriteElementString("Dminfre", "0");
                textWriter.WriteElementString("Dmaxfre", "62");
                textWriter.WriteElementString("PowerDbm", "30");
                //数据上传更新间隔
                textWriter.WriteElementString("UpInterval", "20000");

                // 写文档结束
                textWriter.WriteEndDocument();

                // 关闭textWriter
                textWriter.Close();

            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// Create a temporary XML file that will be send to SAP application
        /// </summary>
        /// <param name="m"></param>
        /// <param name="filePath"></param>
        internal void Export(Canguro.Model.Model m, string filePath)
        {
            String xmlfile = filePath.Substring(0, filePath.Length - 3) + "xml";
            tmpxml = new XmlTextWriter(xmlfile, null);
            Canguro.Model.UnitSystem.UnitSystem uSystem = m.UnitSystem;
            m.UnitSystem = Canguro.Model.UnitSystem.InternationalSystem.Instance;

            try {
                tmpxml.Formatting = Formatting.Indented;
                tmpxml.Indentation = 4;
                tmpxml.Namespaces = false;
                tmpxml.WriteStartDocument();
                tmpxml.WriteComment("XML file generated by CanguroTeam");
                tmpxml.WriteComment(DateTime.Now.ToString());
                // node added for validation
                tmpxml.WriteStartElement("XmlExportedFile");
                // writing fix values for nodes
                writeFixedNode(tmpxml);
                //writing nodes for Joints
                writeNode(tmpxml, m.JointList);
                //writing nodes for Lines
                writeNode(tmpxml, m.LineList);
                //writing xml nodes for Materials
                writeNode(tmpxml);
                //writing xml nodes for Abstract cases
                writeNode(tmpxml, m);
                //writing xml nodes for Load cases
                writeNode(tmpxml, m.LoadCases);
                //writing xml nodes for concrete material
                writeConcreteNode(tmpxml, m.ConcreteDesignOptions);
                //writing xml nodes for steel material
                writeSteelNode(tmpxml, m.SteelDesignOptions);
                //writing xml nodes for frame design
                writeFrameDesignNode(tmpxml, m);
                //writing nodes for spectrum analysis
                writeNode(tmpxml, m.ResponseSpectra, m.AbstractCases);
                tmpxml.WriteEndElement();
                tmpxml.Flush();
            } catch(Exception e) {
                System.Windows.Forms.MessageBox.Show(Culture.Get("XmlError"), Culture.Get("error"),
                System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                throw;
            } finally {
                if (tmpxml != null) {
                    tmpxml.Close();
                    m.UnitSystem = uSystem;
                }
            }
        }
 public static void XMLWriterInit(XmlTextWriter XWriter)
 {
     XWriter.Formatting = Formatting.Indented;
     XWriter.WriteStartDocument();
     XWriter.WriteComment("XMLSerialised XBIM geometry");
     XWriter.WriteStartElement("XBIMGeometry");
 }
        /// <summary>
        /// Update XML Interplay, with count value.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, System.EventArgs e)
        {
            count = Convert.ToInt32(this.numericUpDown.Value);

            try
            {
                using (XmlTextWriter counter = new XmlTextWriter("Interplay.xml", System.Text.Encoding.Default))
                {
                    counter.WriteStartDocument(true);
                    counter.WriteComment("Just a small xml, dealing with the number of times a computer vs. computer would play");
                    counter.WriteStartElement("count");
                    counter.WriteString(this.numericUpDown.Value.ToString());
                    counter.WriteEndElement();
                    counter.WriteEndDocument();
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                //do nothing, use defaults
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Close();
        }
Beispiel #6
0
        internal string Build()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlTextWriter xml = new XmlTextWriter(ms, new UTF8Encoding(false)) { Formatting = Formatting.Indented })
                {
                    xml.WriteStartDocument();

                    string license = this.GetLicense();
                    xml.WriteComment(license);

                    xml.WriteStartElement("MixERPReport");
                    xml.WriteElementString("Title", this.Definition.Title);

                    this.WriteTopSection(xml);
                    this.WriteBody(xml);
                    this.WriteBottomSection(xml);

                    this.WriteDataSources(xml);

                    this.WriteMenu(xml);
                }

                return Encoding.UTF8.GetString(ms.ToArray());
            }
        }
Beispiel #7
0
        public void Dump2Xml()
        {
            if ( ( TheHt.Count <= 0 ) || !IsDirty )
             {
            Announce( "Cache not dirty" );
            return;
             }

             Announce( string.Format( "Writing cache to {0}", Filename ) );

             Utility.EnsureDirectory( Filename );  //  will create the dir if its not there

             var writer = new XmlTextWriter( Filename, null );

             writer.WriteStartDocument();
             writer.WriteComment( "Comments: " + Name );
             writer.WriteStartElement( "stat-list" );

             var myEnumerator = TheHt.GetEnumerator();
             while ( myEnumerator.MoveNext() )
             {
            var t = ( YahooOutput ) myEnumerator.Value;
            WriteStatNode( writer, t );
             }
             writer.WriteEndElement();
             writer.WriteEndDocument();
             writer.Close();
        }
Beispiel #8
0
 public void Save_XML(string path)
 {
     XmlTextWriter xmlTextWriter = new XmlTextWriter(path, null);
     xmlTextWriter.Formatting = Formatting.Indented;
     xmlTextWriter.WriteStartDocument(false);
     xmlTextWriter.WriteComment("Xml from Juan converter");
     xmlTextWriter.WriteStartElement("STB");
     for (int num = 0; num != this.rowcount; num++)
     {
         xmlTextWriter.WriteStartElement("Entry");
         xmlTextWriter.WriteAttributeString("id", num.ToString());
         for (int num2 = 0; num2 != this.columncount; num2++)
         {
             if (this.column[num2].selected)
             {
                 xmlTextWriter.WriteStartElement("Data");
                 xmlTextWriter.WriteAttributeString("type", this.column[num2].columntitle);
                 xmlTextWriter.WriteString(this.celldata[num, num2]);
                 xmlTextWriter.WriteEndElement();
             }
         }
         xmlTextWriter.WriteEndElement();
     }
     xmlTextWriter.WriteEndElement();
     xmlTextWriter.Flush();
     xmlTextWriter.Close();
     xmlTextWriter.Close();
 }
Beispiel #9
0
        public void Dump2Xml()
        {
            if (_gameHt.Count > 0)
            {
                //DumpHt( gameHT );

                var writer = new
                    XmlTextWriter(string.Format("{0}\\xml\\NFLGame.xml", Utility.OutputDirectory()), null);

                writer.WriteStartDocument();
                writer.WriteComment("Comments: Game Metrics");
                writer.WriteStartElement("game-list");

                var myEnumerator = _gameHt.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    var g = (NFLGame) myEnumerator.Value;
                    WriteGameNode(writer, g);
                    if (g.GameDate >= DateTime.Now) continue;
                    if (g.AwayScore + g.HomeScore == 0)
                        Utility.Announce(string.Format("Suspect game [{0}]:", g.ScoreOut()));
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                Utility.Announce(string.Format("   {0}\\xml\\NFLGame.xml created", Utility.OutputDirectory()));
            }
        }
        public override bool Execute()
        {
            string pdbxmlFile = Path.ChangeExtension(AssemblyName.ItemSpec, ".pdb.xml");
            _pddxmlFile = new TaskItem(pdbxmlFile);
            xwriter = new XmlTextWriter(pdbxmlFile, null);
            xwriter.Formatting = Formatting.Indented;

            //Log.LogMessage("Get symbol reader for file {0}", Path.ChangeExtension(AssemblyName.ItemSpec, ".pdb"));
            ISymbolReader reader = SymUtil.GetSymbolReaderForFile(AssemblyName.ItemSpec, null);
            //Log.LogMessage("Load assembly");
            m_assembly = System.Reflection.Assembly.LoadFrom(AssemblyName.ItemSpec);

            // Begin writing XML.
            xwriter.WriteStartDocument();
            xwriter.WriteComment("This is an XML file representing the PDB for '" + AssemblyName.ItemSpec + "'");
            xwriter.WriteStartElement("Types");

            // Record what input file these symbols are for.
            xwriter.WriteAttributeString("file", AssemblyName.ItemSpec);

            //WriteDocList(reader);
            WriteTypesAndDocs(reader);

            xwriter.WriteEndElement(); // "Symbols";
            xwriter.Close();

            return !Log.HasLoggedErrors;
        }
Beispiel #11
0
        public void Save(string path)
        {
            XmlTextWriter myXmlTextWriter = new XmlTextWriter(path, System.Text.Encoding.UTF8);
            myXmlTextWriter.Formatting = Formatting.Indented;
            myXmlTextWriter.WriteStartDocument(false);

            myXmlTextWriter.WriteComment("Erstellt von gamenoise");

            myXmlTextWriter.WriteStartElement("streams");

            IEnumerator enumerator = _myStreams.GetEnumerator();

            while (enumerator.MoveNext())
            {
                myXmlTextWriter.WriteStartElement("stream");

                myXmlTextWriter.WriteElementString("title", ((Stream)enumerator.Current).Title);
                myXmlTextWriter.WriteElementString("url", ((Stream)enumerator.Current).Url);
                myXmlTextWriter.WriteElementString("genre", ((Stream)enumerator.Current).Genre);
                myXmlTextWriter.WriteElementString("description", ((Stream)enumerator.Current).Description);

                myXmlTextWriter.WriteEndElement();
            }

            myXmlTextWriter.WriteEndElement();

            myXmlTextWriter.Flush();
            myXmlTextWriter.Close();
        }
Beispiel #12
0
 public static void WriteXmlInFile(string layer, string msg)
 {
     try
     {
         //XmlDataDocument sourceXML = new XmlDataDocument();
         string xmlFile = HttpContext.Current.Server.MapPath("/log/Exception.xml");
         //create a XML file is not exist
         System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(xmlFile, null);
         //starts a new document
         writer.WriteStartDocument();
         //write comments
         writer.WriteComment("Commentss: XmlWriter Test Program");
         writer.Formatting = Formatting.Indented;
         writer.WriteStartElement("MessageList");
         writer.WriteStartElement("Exception");
         writer.WriteAttributeString("Layer", layer);
         //write some simple elements
         writer.WriteElementString("Message", msg);
         writer.WriteEndElement();
         writer.WriteEndElement();
         writer.WriteEndElement();
         writer.Close();
     }
     catch (Exception ex) { throw ex; }
 }
Beispiel #13
0
        public void CreateXml()
        {
            if ( ( m_SeasonList.Count > 0 ) )
            {
                const string fileName = "NFL.xml";
                XmlTextWriter writer = new
                    XmlTextWriter(string.Format("{0}{1}", Utility.OutputDirectory() + "xml\\", fileName), null);
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteComment( "Comments: NFL Season List" );
                writer.WriteStartElement( "nfl" );
                writer.WriteStartElement("season-list");

                foreach ( NflSeason s in m_SeasonList )
                {
                    WriteSeasonNode( writer, s );
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                RosterLib.Utility.Announce( fileName + " created" );
            }
        }
Beispiel #14
0
        /// <summary>
        ///   Converts the memory hash table to XML
        /// </summary>
        public void Dump2Xml()
        {
            if ( ( TheHT.Count > 0 ) && IsDirty )
            {
                XmlTextWriter writer = new
                          XmlTextWriter( string.Format( "{0}", Filename ), null );

                writer.WriteStartDocument();
                writer.WriteComment( "Comments: " + Name );
                writer.WriteStartElement( "media-list" );

                IDictionaryEnumerator myEnumerator = TheHT.GetEnumerator();
                while ( myEnumerator.MoveNext() )
                {
                    MediaItem m = (MediaItem) myEnumerator.Value;
                    WriteMediaNode( writer, m );
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                Utility.Announce( string.Format( "{0} created.",  Filename ) );
            }
            else
                Utility.Announce( string.Format( "No changes to {0}.", Filename ) );
        }
Beispiel #15
0
        /// <summary>
        ///   Converts the memory hash table to XML
        /// </summary>
        public void Dump2Xml()
        {
            if ((TheHt.Count > 0) && IsDirty)
             {
            var writer = new XmlTextWriter(string.Format("{0}", Filename), null);
            writer.Formatting = Formatting.Indented;
            writer.WriteStartDocument();

            writer.WriteComment("Comments: " + Name);
            writer.WriteStartElement("logfile-list");

            var myEnumerator = TheHt.GetEnumerator();
            while (myEnumerator.MoveNext())
            {
               var m = (LogItem)myEnumerator.Value;
               WriteLogNode(writer, m);
            }
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
            Utility.Announce(string.Format("{0} created.", Filename));
             }
             else
            Utility.Announce(string.Format("No changes to {0}.", Filename));
        }
Beispiel #16
0
        public void exportTopic(string p_ID, Topic p_Topic)
        {
            Settings l_Settings = Settings.Instance;
            //File overwritten when already existing
            XmlTextWriter l_Writer = new XmlTextWriter(l_Settings.TopicsDir + p_ID + ".xml", Encoding.UTF8);
            l_Writer.Formatting = Formatting.Indented;

            try
            {
                l_Writer.WriteStartDocument();
                l_Writer.WriteComment("ggplot2 topic.");
                l_Writer.WriteStartElement("Topic");

                l_Writer.WriteStartElement("Title");
                l_Writer.WriteString(p_Topic.Title);
                l_Writer.WriteEndElement();
                l_Writer.WriteStartElement("ID");
                l_Writer.WriteString(p_Topic.ID);
                l_Writer.WriteEndElement();
                l_Writer.WriteStartElement("Messages");

                for (int j = 0; j < p_Topic.Messages.Count; j++)
                {
                    l_Writer.WriteStartElement("Message");
                    l_Writer.WriteStartElement("User");
                    l_Writer.WriteStartElement("Name");
                    l_Writer.WriteString(p_Topic.Messages[j].UserName);
                    l_Writer.WriteEndElement();
                    l_Writer.WriteStartElement("Avatar");
                    l_Writer.WriteString(p_Topic.Messages[j].Avatar);
                    l_Writer.WriteEndElement();
                    l_Writer.WriteStartElement("Email");
                    l_Writer.WriteString(p_Topic.Messages[j].Email);
                    l_Writer.WriteEndElement();
                    l_Writer.WriteEndElement();//~User
                    l_Writer.WriteStartElement("date");
                    l_Writer.WriteString(p_Topic.Messages[j].Date);
                    l_Writer.WriteEndElement();
                    l_Writer.WriteStartElement("content");
                    l_Writer.WriteString(p_Topic.Messages[j].Content);
                    l_Writer.WriteEndElement();
                    l_Writer.WriteEndElement();//~Message
                }

                l_Writer.WriteEndElement();//~Messages
                l_Writer.WriteEndElement();//~Topic

                l_Writer.WriteEndDocument();
                l_Writer.Flush();
                l_Writer.Close();
            }
            catch (Exception e)
            {
                l_Writer.Flush();
                l_Writer.Close();
                if (l_Settings.DebugMode)
                    debug("Exception in exportTopic(): " + e.Message);
            }
        }
        //In order to write to XML file this function needs to be called
        public void openXmlWriter(string fileName, string applicationComment)
        {
            xmlWriter = new XmlTextWriter(fileName, Encoding.UTF8);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteComment(applicationComment);
            xmlWriter.WriteStartElement("Settings");
        }
Beispiel #18
0
        public void save_to_xml(string filename)
        {
            XmlTextWriter tw = new XmlTextWriter(filename, null);
            tw.Formatting = Formatting.Indented;
            tw.Indentation = 4;
            tw.WriteStartDocument();

            // Get the name and version of the current assembly.
            Assembly assem = Assembly.GetExecutingAssembly();
            AssemblyName assemName = assem.GetName();
            Version ver = assemName.Version;
            tw.WriteComment(String.Format("{0}, Version {1}", assemName.Name, ver.ToString()));
            tw.WriteComment("GUI Settings");
            tw.WriteComment("Do not change this file manually, unless you know what are you doing");

            tw.WriteStartElement("PARAMETERS");

            tw.WriteStartElement("FCVERSION value=\"" + iSoftwareVersion + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGFOLDER value=\"" + sLogFolder + "\""); tw.WriteEndElement();
            tw.WriteStartElement("CAPTUREFOLDER value=\"" + sCaptureFolder + "\""); tw.WriteEndElement();
            tw.WriteStartElement("SETTINGSFOLDER value=\"" + sSettingsFolder + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGATCONNECT value=\"" + bEnableLogging + "\""); tw.WriteEndElement();
            tw.WriteStartElement("SERIALPORT value=\"" + sPreferedComPort + "\""); tw.WriteEndElement();
            tw.WriteStartElement("SERIALSPEED value=\"" + sPreferedSerialSpeed + "\""); tw.WriteEndElement();

            tw.WriteStartElement("LOGRAW value=\"" + logGraw + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGATT value=\"" + logGatt + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGMAG value=\"" + logGmag + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGRCC value=\"" + logGrcc + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGRCX value=\"" + logGrcx + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGMOT value=\"" + logGmot + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGSRV value=\"" + logGsrv + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGNAV value=\"" + logGnav + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGPAR value=\"" + logGpar + "\""); tw.WriteEndElement();
            tw.WriteStartElement("LOGDBG value=\"" + logGdbg + "\""); tw.WriteEndElement();

            tw.WriteComment("Change this to TRUE if you using 20120203 release, this will depreciate serial protocol change in SVN r569");
            tw.WriteComment("This will work only when FCVERSION==20");
            tw.WriteStartElement("SUPRESSI2CERRORDATA value=\"" + bSupressI2CErrorData + "\""); tw.WriteEndElement();

            tw.WriteEndElement();

            tw.WriteEndDocument();
            tw.Close();
        }
Beispiel #19
0
        public void save_to_xml(string filename)
        {
            XmlTextWriter tw = new XmlTextWriter(filename, null);
            tw.Formatting = Formatting.Indented;
            tw.Indentation = 4;
            tw.WriteStartDocument();

            // Get the name and version of the current assembly.
            Assembly assem = Assembly.GetExecutingAssembly();
            AssemblyName assemName = assem.GetName();
            Version ver = assemName.Version;
            tw.WriteComment(String.Format("{0}, Version {1}", assemName.Name, ver.ToString()));
            tw.WriteComment("GUI Settings");
            tw.WriteComment("Do not change this file manually, unless you know what are you doing");

            tw.WriteStartElement("PARAMETERS");

            tw.WriteStartElement("FCVERSION value=\"" + iSoftwareVersion + "\""); tw.WriteEndElement();
            tw.WriteStartElement("SETTINGSFOLDER value=\"" + sSettingsFolder + "\""); tw.WriteEndElement();

            tw.WriteStartElement("MSP_STATUS_RATE_DIV value=\"" + MSP_STATUS_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_RAW_IMU_RATE_DIV value=\"" + MSP_RAW_IMU_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_SERVO_RATE_DIV value=\"" + MSP_SERVO_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_MOTOR_RATE_DIV value=\"" + MSP_MOTOR_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_RAW_GPS_RATE_DIV value=\"" + MSP_RAW_GPS_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_COMP_GPS_RATE_DIV value=\"" + MSP_COMP_GPS_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_ATTITUDE_RATE_DIV value=\"" + MSP_ATTITUDE_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_ALTITUDE_RATE_DIV value=\"" + MSP_ALTITUDE_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_BAT_RATE_DIV value=\"" + MSP_BAT_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_RC_RATE_DIV value=\"" + MSP_RC_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_MISC_RATE_DIV value=\"" + MSP_MISC_rate_divider + "\""); tw.WriteEndElement();
            tw.WriteStartElement("MSP_DEBUG_RATE_DIV value=\"" + MSP_DEBUG_rate_divider + "\""); tw.WriteEndElement();

            tw.WriteEndElement();

            tw.WriteEndDocument();
            tw.Close();
        }
		public FrmVideo()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			// Create an XmlTextWriter object and initialize a few 
			// properties.
            xtw = new XmlTextWriter(@"c:\Videos.xml", null);

            xtw.Formatting = Formatting.Indented;
            xtw.Indentation = 3;

			// Start the XML document.
            xtw.WriteStartDocument();  
    
            xtw.WriteComment("Video Library");
			xtw.WriteComment(
				"This is a file containing a number of videos.");
			// Create the root element.
            xtw.WriteStartElement("VideoLibrary");
		}
Beispiel #21
0
        //creating config file
        public static void WriteXML(string steam, string dota)
        {
            XmlTextWriter myXmlTextWriter = new XmlTextWriter("config.xml", null);
            myXmlTextWriter.Formatting = Formatting.Indented;
            myXmlTextWriter.WriteStartDocument(false);
            myXmlTextWriter.WriteComment("This is the configuration file. You can change manually, but it may crash.");

            myXmlTextWriter.WriteStartElement("GlobalPaths");
            myXmlTextWriter.WriteElementString("Steam", steam);
            myXmlTextWriter.WriteElementString("Dota", dota);
            myXmlTextWriter.WriteEndElement();

            myXmlTextWriter.Flush();
            myXmlTextWriter.Close();
        }
Beispiel #22
0
        public void exportStats(List<User> p_Users)
        {
            Settings l_Settings = Settings.Instance;
            XmlTextWriter l_Writer = new XmlTextWriter(l_Settings.OutputDir + l_Settings.StatsFile, Encoding.UTF8);
            l_Writer.Formatting = Formatting.Indented;
            TextWriter l_WriterCsv = new StreamWriter(l_Settings.OutputDir + "GG_stats.csv", false, Encoding.UTF8);
            string l_Delimiter = ";";

            try
            {
                l_Writer.WriteStartDocument();
                l_Writer.WriteComment("ggplot2 " + p_Users.Count + " user stats.");
                l_Writer.WriteStartElement("Users");
                l_WriterCsv.WriteLine("Id" + l_Delimiter + "Answers" + l_Delimiter + "Questions" + l_Delimiter + "ZScore" + l_Delimiter + "InDegree" + l_Delimiter + "OutDegree" + l_Delimiter + "ZDegree" + l_Delimiter + "ExertiseRank");

                for (int i = 0; i < p_Users.Count; i++)
                {
                    l_Writer.WriteStartElement("User");

                    l_Writer.WriteAttributeString("Id", i.ToString());
                    l_Writer.WriteAttributeString("Answers", p_Users[i].Answers.ToString());
                    l_Writer.WriteAttributeString("Questions", p_Users[i].Questions.ToString());
                    l_Writer.WriteAttributeString("ZScore", p_Users[i].ZScore.ToString());
                    l_Writer.WriteAttributeString("InDegree", p_Users[i].InDegreeList.Count.ToString());
                    l_Writer.WriteAttributeString("OutDegree", p_Users[i].OutDegreeList.Count.ToString());
                    l_Writer.WriteAttributeString("ZDegree", p_Users[i].ZDegree.ToString());
                    l_Writer.WriteAttributeString("ExpertiseRank", p_Users[i].ExpertiseRank.ToString());

                    l_Writer.WriteEndElement();

                    l_WriterCsv.WriteLine(i.ToString() + l_Delimiter + p_Users[i].Answers.ToString() + l_Delimiter + p_Users[i].Questions.ToString() + l_Delimiter + p_Users[i].ZScore.ToString() + l_Delimiter + p_Users[i].InDegreeList.Count.ToString() + l_Delimiter + p_Users[i].OutDegreeList.Count.ToString() + l_Delimiter + p_Users[i].ZDegree.ToString() + l_Delimiter + p_Users[i].ExpertiseRank.ToString());
                }

                l_Writer.WriteEndElement();//~Users
                l_Writer.WriteEndDocument();
                l_Writer.Flush();
                l_Writer.Close();
                l_WriterCsv.Close();
            }
            catch (Exception e)
            {
                l_Writer.Flush();
                l_Writer.Close();
                l_WriterCsv.Close();
                if (l_Settings.DebugMode)
                    debug("Exception in exportStats(): " + e.Message);
            }
        }
Beispiel #23
0
        //--Methods
        public void exportStats(List<User> p_Users)
        {
            XmlTextWriter l_Writer = new XmlTextWriter("GH_stats.xml", Encoding.UTF8);
            TextWriter l_WriterCsv = new StreamWriter("GH_stats.csv", false, Encoding.UTF8);
            l_Writer.Formatting = Formatting.Indented;
            string l_Delimiter = ";";

            try
            {
                l_Writer.WriteStartDocument();
                l_Writer.WriteComment("GitHub " + p_Users.Count + " user stats.");
                l_Writer.WriteStartElement("Users");
                l_WriterCsv.WriteLine("Id" + l_Delimiter + "Answers" + l_Delimiter + "Questions" + l_Delimiter + "ZScore" + l_Delimiter + "InDegree" + l_Delimiter + "OutDegree" + l_Delimiter + "ZDegree" + l_Delimiter + "ExertiseRank");

                for (int i = 0; i < p_Users.Count; i++)
                {
                    l_Writer.WriteStartElement("User");

                    l_Writer.WriteAttributeString("Id", p_Users[i].Id);
                    l_Writer.WriteAttributeString("Answers", p_Users[i].Answers.ToString());
                    l_Writer.WriteAttributeString("Questions", p_Users[i].Questions.ToString());
                    l_Writer.WriteAttributeString("ZScore", p_Users[i].ZScore.ToString());
                    l_Writer.WriteAttributeString("InDegree", p_Users[i].InDegreeList.Count.ToString());
                    l_Writer.WriteAttributeString("OutDegree", p_Users[i].OutDegreeList.Count.ToString());
                    l_Writer.WriteAttributeString("ZDegree", p_Users[i].ZDegree.ToString());
                    l_Writer.WriteAttributeString("ExpertiseRank", p_Users[i].ExpertiseRank.ToString());

                    l_Writer.WriteEndElement();

                    l_WriterCsv.WriteLine(p_Users[i].Id + l_Delimiter + p_Users[i].Answers.ToString() + l_Delimiter + p_Users[i].Questions.ToString() + l_Delimiter + p_Users[i].ZScore.ToString() + l_Delimiter + p_Users[i].InDegreeList.Count.ToString() + l_Delimiter + p_Users[i].OutDegreeList.Count.ToString() + l_Delimiter + p_Users[i].ZDegree.ToString() + l_Delimiter + p_Users[i].ExpertiseRank.ToString());
                }

                l_Writer.WriteEndElement();//~Users
                l_Writer.WriteEndDocument();
                l_Writer.Flush();
                l_Writer.Close();
                l_WriterCsv.Close();
            }
            catch (Exception e)
            {
                l_Writer.Flush();
                l_Writer.Close();
                l_WriterCsv.Close();
                Console.WriteLine("---> Exception in exportStats(): " + e.Message);
            }
        }
		///	<summary>
		///	写 XML
		///	</summary>
		public void	WriteXml()
		{
			// 构造写入类.
			// 第一个参数为 文件名
			// 第二个参数为编码方式.
			XmlTextWriter writer = new XmlTextWriter(XML_FILE_NAME,	Encoding.UTF8);

			//使用自动缩进便于阅读
			writer.Formatting =	Formatting.Indented;

			// 书写版本为“1.0”的 XML 声明
			writer.WriteStartDocument();


			// 写注释
			writer.WriteComment("XML文件写入的例子!");

			//写入根元素
			writer.WriteStartElement("items");

			// 加入属性: type="IT"
			writer.WriteStartAttribute("type");
			writer.WriteString("information");
			writer.WriteEndAttribute();

			writer.WriteStartAttribute("keyword");
			writer.WriteString("Database");
			writer.WriteEndAttribute();


			// 加入子元素: <title>SQL Server</title>	这种方式的。
			writer.WriteElementString("title", "SQL	Server");
			writer.WriteElementString("title", "Oracle");
			writer.WriteElementString("title", "MySQL");


			//关闭根元素,并书写结束标签
			writer.WriteEndElement();

			// 关闭任何打开的元素或属性
			writer.WriteEndDocument();

			//将XML写入文件并且关闭XmlTextWriter
			writer.Close();
		}
Beispiel #25
0
        public void saveSetting(string vsSettingsFile)
        {
            if (vsSettingsFile == null) return;

            string fullDirPath = Path.GetDirectoryName(vsSettingsFile);

            try
            {
                if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
            }
            catch { }

            // open file
            FileStream fs = new FileStream(vsSettingsFile, FileMode.Create);

            // create XML writer
            XmlTextWriter xmlOut = new XmlTextWriter(fs, Encoding.UTF8);

            // use indenting for readability
            xmlOut.Formatting = Formatting.Indented;

            // start document
            xmlOut.WriteStartDocument();
            xmlOut.WriteComment("Visual Surveillance System configuration file");

            // main node
            xmlOut.WriteStartElement("appSettings");
            {
                foreach (KeyValuePair<string, string> kv in data)
                {
                    xmlOut.WriteStartElement("add");
                    {
                        xmlOut.WriteAttributeString("key", kv.Key);
                        xmlOut.WriteAttributeString("value", kv.Value);

                    }
                    xmlOut.WriteEndElement();
                }
            }
            xmlOut.WriteEndElement();

            // close file
            xmlOut.Close();
            fs.Close();
        }
Beispiel #26
0
        /// <summary>
        /// װ��Xml�ĵ�����������򴴽�
        /// </summary>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static XmlDocument Load(string filepath)
        {
            string path = Path.GetDirectoryName(filepath);
            string filename = Path.GetFileName(filepath);
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            if (!File.Exists(filepath))
            {
                XmlTextWriter writer = null;

                writer = new XmlTextWriter(filepath, Encoding.UTF8);

                //Write the XML delcaration.
                writer.WriteStartDocument();

                //Write the ProcessingInstruction node.
                String PItext = "type='text/xsl'";
                writer.WriteProcessingInstruction("xml-stylesheet", PItext);

                //Write a Comment node.
                writer.WriteComment("user XML");

                writer.WriteStartElement(filename.Substring(0, filename.LastIndexOf('.')));
                writer.WriteAttributeString("UpdateDate", DateTime.Now.ToString());

                writer.WriteEndElement();

                writer.WriteEndDocument();

                //Write the XML to file and close the writer.
                writer.Flush();
                writer.Close();
            }
            XmlDocument doc = new XmlDocument();
            while (true)
            {
                try
                {
                    doc.Load(filepath);
                    return doc;
                }
                catch { }
            }
        }
Beispiel #27
0
 public static void WriteBans(string[] toWrite)
 {
     if (File.Exists("banned.xml") == true)
     {
         File.Delete("banned.xml");
     }
     XmlTextWriter banWriter = new XmlTextWriter("banned.xml", null); //Create new XML file ready for output
     banWriter.WriteStartDocument();
     banWriter.WriteComment("Time Bans for MGUI");
     banWriter.WriteStartElement("Banned");
     foreach (string s in toWrite)
     {
         banWriter.WriteString(s);
     }
     banWriter.WriteEndElement();
     banWriter.WriteEndDocument();
     banWriter.Close();
 }
Beispiel #28
0
        /// <summary>
        /// Запись кэша меток в отдельный XML файл
        /// </summary>
        /// <param name="buf">Кэш меток</param>
        /// <param name="fname">Полный путь и название файла для сохранения</param>
        public static void SaveLabelsCacheToXMLFile(LabelsCache buf, string fname)
        {
            XmlTextWriter file = new XmlTextWriter(fname, Encoding.UTF8);

            file.WriteStartDocument();
            file.WriteComment("Definition of labels cache data");
            file.WriteStartElement("labels");
            for (int i = 0; i < buf.GetLabelsCount; i++)
            {
                file.WriteStartElement("label");
                file.WriteStartAttribute("value");
                file.WriteValue(buf[i]);
                file.WriteEndElement();
            }
            file.WriteEndElement();

            file.Close();
        }
Beispiel #29
0
        public void CreateFile()
        {
            if (File.Exists(FILE_NAME))
               {
               return;
               }

               var newXml = new XmlTextWriter(FILE_NAME, null);

               newXml.WriteStartDocument();
               newXml.WriteComment("Nazwa pliku " + FILE_NAME);
               newXml.WriteStartElement("RSS");
               newXml.WriteAttributeString("data", DateTime.Now.ToString(CultureInfo.InvariantCulture).Substring(0, 10));
               newXml.WriteAttributeString("godzina", DateTime.Now.ToString(CultureInfo.InvariantCulture).Substring(11));
               newXml.WriteEndElement();

               newXml.Close();
        }
        public static void AggiornaDatabase()
        {
            lock (string.Intern("AggiornaDatabase"))
            {
                string avviso;

                //Operazioni effettuate una sola volta al giorno
                DateTime dataOdierna = DateTime.Parse(Configurazione.GetItem(Configurazione.ConfigurazioneEnum.Today).Valore);
                if (dataOdierna.Date < DateTime.Now.Date)
                {
                    //Aggiorno la data
                    var imp = Configurazione.GetItem(Configurazione.ConfigurazioneEnum.Today);
                    imp.Valore = DateTime.Now.Date.ToShortDateString();
                    Configurazione.Save(out avviso, ref imp);

                    #region Sitemap per google

                    //Creo una siteMap per ogni sito
                    FileStream siteMapGoogle = new FileStream(Common.Settings.Config.DiskPath + "\\sitemap.xml", FileMode.Create, FileAccess.Write);

                    XmlTextWriter xmlTextWriter = new XmlTextWriter(siteMapGoogle, Encoding.UTF8) { Formatting = Formatting.Indented };
                    xmlTextWriter.WriteStartDocument();
                    xmlTextWriter.WriteComment("Sitemap generata automaticamente, " + DateTime.Now.ToLongDateString());
                    xmlTextWriter.WriteStartElement("urlset", "http://www.google.com/schemas/sitemap/0.84");

                    var eventiCollection = EventiCollection.GetList(orderPredicate: "Data ASC");
                    foreach (var evento in eventiCollection)
                    {
                        xmlTextWriter.WriteStartElement("url");
                        xmlTextWriter.WriteElementString("loc", "http://www.bluestaff.it/evento/" + evento.Titolo.Replace(" ", "_") + "-" + evento.Id);
                        xmlTextWriter.WriteElementString("lastmod", evento.Data.ToString("s") + "+00:00");
                        xmlTextWriter.WriteElementString("changefreq", "weekly");
                        xmlTextWriter.WriteEndElement();
                    }

                    xmlTextWriter.WriteEndElement(); //</urlset>
                    xmlTextWriter.WriteEndDocument();
                    xmlTextWriter.Close();
                    siteMapGoogle.Dispose();

                    #endregion
                }
            }
        }
Beispiel #31
0
        // dump all the data to XML
        public static void SaveData()
        {
            XmlTextWriter writer = null;
            try
            {
                writer = new XmlTextWriter("data.xml", Encoding.UTF8);
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("I don't have permission to write in file: data.xml", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            writer.Formatting = Formatting.Indented;
            writer.Indentation = 1; // one tab Indentation
            writer.IndentChar = '\t';
            writer.WriteStartDocument();
            writer.WriteComment(" RealmChanger by anuka - http://github.com/Anubisss "); // just comment the author
            writer.WriteStartElement("RealmChangerData"); // root element

            writer.WriteStartElement("RealmListData"); // list of realmlists
            foreach (KeyValuePair<String, String> pair in RealmList.List)
            {
                writer.WriteStartElement("RealmList");
                writer.WriteElementString("RealmListName", pair.Key);
                writer.WriteElementString("RealmListAddress", pair.Value);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteStartElement("WTFListData"); // list of WTFlists
            foreach (KeyValuePair<String, String> pair in WtfList.List)
            {
                writer.WriteStartElement("WTF");
                writer.WriteElementString("WTFName", pair.Key);
                writer.WriteElementString("WTFLocation", pair.Value);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
        }
        /// <summary> Writes the mapping of the specified class in the specified stream. </summary>
        /// <param name="stream">Where the xml is written; can be null if you send the writer.</param>
        /// <param name="type">User-defined type containing a valid attribute (can be [Class] or [xSubclass]).</param>
        /// <param name="writer">The XmlTextWriter used to write the xml; can be null if you send the stream. You can also create it yourself, but don't forget to write the StartElement ("hibernate-mapping") before.</param>
        /// <param name="writeEndDocument">Tells if the EndElement of "hibernate-mapping" must be written; send false to append many classes in the same stream.</param>
        /// <returns>The parameter writer if it was not null; else it is a new writer (created using the stream). Send it back to append many classes in this stream.</returns>
        public virtual System.Xml.XmlTextWriter Serialize(System.IO.Stream stream, System.Type type, System.Xml.XmlTextWriter writer, bool writeEndDocument)
        {
            if (stream == null && writer == null)
            {
                throw new System.ArgumentNullException("stream");
            }
            if (type == null)
            {
                throw new System.ArgumentNullException("type");
            }

            if (writer == null)
            {
                writer            = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
                writer.Formatting = System.Xml.Formatting.Indented;
                writer.WriteStartDocument();
                if (WriteDateComment)
                {
                    writer.WriteComment(string.Format("Generated by NHibernate.Mapping.Attributes on {0}.", System.DateTime.Now.ToString("u")));
                }
                WriteHibernateMapping(writer, type);
            }

            if (IsClass(type))
            {
                HbmWriter.WriteClass(writer, type);
            }
            else if (IsSubclass(type, typeof(SubclassAttribute)))
            {
                HbmWriter.WriteSubclass(writer, type);
            }
            else if (IsSubclass(type, typeof(JoinedSubclassAttribute)))
            {
                HbmWriter.WriteJoinedSubclass(writer, type);
            }
            else if (IsSubclass(type, typeof(UnionSubclassAttribute)))
            {
                HbmWriter.WriteUnionSubclass(writer, type);
            }
            else
            {
                throw new System.ArgumentException("No valid attribute; looking for [Class] or [xSubclass].", "type");
            }

            if (writeEndDocument)
            {
                writer.WriteEndElement();                 // </hibernate-mapping>
                writer.WriteEndDocument();
                writer.Flush();

                if (!Validate)
                {
                    return(writer);
                }

                // Validate the generated XML stream
                try
                {
                    writer.BaseStream.Position = 0;
                    var tr     = new System.Xml.XmlTextReader(writer.BaseStream);
                    var reader = CreateReader(tr);

                    _stop = false;
                    while (reader.Read() && !_stop)                    // Read to validate (stop at the first error)
                    {
                        ;
                    }
                }
                catch (System.Exception ex)
                {
                    Error.Append(ex.ToString()).Append(System.Environment.NewLine + System.Environment.NewLine);
                }
            }
            else
            {
                writer.Flush();
            }

            return(writer);
        }
        /// <summary> Writes the mapping of all mapped classes of the specified assembly in the specified stream. </summary>
        /// <param name="stream">Where the xml is written.</param>
        /// <param name="assembly">Assembly used to extract user-defined types containing a valid attribute (can be [Class] or [xSubclass]).</param>
        public virtual void Serialize(System.IO.Stream stream, System.Reflection.Assembly assembly)
        {
            if (stream == null)
            {
                throw new System.ArgumentNullException("stream");
            }
            if (assembly == null)
            {
                throw new System.ArgumentNullException("assembly");
            }

            System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
            writer.Formatting = System.Xml.Formatting.Indented;
            writer.WriteStartDocument();
            if (WriteDateComment)
            {
                writer.WriteComment(string.Format("Generated from NHibernate.Mapping.Attributes on {0}.", System.DateTime.Now.ToString("u")));
            }
            WriteHibernateMapping(writer, null);

            // Write imports (classes decorated with the [ImportAttribute])
            foreach (System.Type type in assembly.GetTypes())
            {
                object[] imports = type.GetCustomAttributes(typeof(ImportAttribute), false);
                foreach (ImportAttribute import in imports)
                {
                    writer.WriteStartElement("import");
                    if (import.Class != null && import.Class != string.Empty)
                    {
                        writer.WriteAttributeString("class", import.Class);
                    }
                    else                     // Assume that it is the current type that must be imported
                    {
                        writer.WriteAttributeString("class", HbmWriterHelper.GetNameWithAssembly(type));
                    }
                    if (import.Rename != null && import.Rename != string.Empty)
                    {
                        writer.WriteAttributeString("rename", import.Rename);
                    }
                    writer.WriteEndElement();
                }
            }

            // Write classes and x-subclasses (classes must come first if inherited by "external" subclasses)
            int classCount = 0;

            System.Collections.ArrayList mappedClassesNames = new System.Collections.ArrayList();
            foreach (System.Type type in assembly.GetTypes())
            {
                if (!IsClass(type))
                {
                    continue;
                }
                HbmWriter.WriteClass(writer, type);
                mappedClassesNames.Add(HbmWriterHelper.GetNameWithAssembly(type));
                classCount++;
            }

            System.Collections.ArrayList subclasses = new System.Collections.ArrayList();
            System.Collections.Specialized.StringCollection extendedClassesNames = new System.Collections.Specialized.StringCollection();
            foreach (System.Type type in assembly.GetTypes())
            {
                if (!IsSubclass(type))
                {
                    continue;
                }
                bool        map = true;
                System.Type t   = type;
                while ((t = t.DeclaringType) != null)
                {
                    if (IsClass(t) || AreSameSubclass(type, t)) // If a base class is also mapped... (Note: A x-subclass can only contain x-subclasses of the same family)
                    {
                        map = false;                            // This class's mapping is already included in the mapping of the base class
                        break;
                    }
                }
                if (map)
                {
                    subclasses.Add(type);
                    if (IsSubclass(type, typeof(SubclassAttribute)))
                    {
                        extendedClassesNames.Add((type.GetCustomAttributes(typeof(SubclassAttribute), false)[0] as SubclassAttribute).Extends);
                    }
                    else if (IsSubclass(type, typeof(JoinedSubclassAttribute)))
                    {
                        extendedClassesNames.Add((type.GetCustomAttributes(typeof(JoinedSubclassAttribute), false)[0] as JoinedSubclassAttribute).Extends);
                    }
                    else if (IsSubclass(type, typeof(UnionSubclassAttribute)))
                    {
                        extendedClassesNames.Add((type.GetCustomAttributes(typeof(UnionSubclassAttribute), false)[0] as UnionSubclassAttribute).Extends);
                    }
                }
            }
            classCount += subclasses.Count;
            MapSubclasses(subclasses, extendedClassesNames, mappedClassesNames, writer);

            writer.WriteEndElement();             // </hibernate-mapping>
            writer.WriteEndDocument();
            writer.Flush();

            if (classCount == 0)
            {
                throw new MappingException("The following assembly contains no mapped classes: " + assembly.FullName);
            }
            if (!Validate)
            {
                return;
            }

            // Validate the generated XML stream
            try
            {
                writer.BaseStream.Position = 0;
                System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(writer.BaseStream);

                var reader = CreateReader(tr);

                _stop = false;
                while (reader.Read() && !_stop)                // Read to validate (stop at the first error)
                {
                    ;
                }
            }
            catch (System.Exception ex)
            {
                Error.Append(ex.ToString()).Append(System.Environment.NewLine + System.Environment.NewLine);
            }
        }
Beispiel #34
0
        /// <summary>
        /// 将DataTable的内容写入到XML文件中
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="address">XML文件地址</param>
        public static bool DBWriteToXml(System.Data.DataTable dt, string address)
        {
            try
            {
                //如果文件DataTable.xml存在则直接删除
                if (System.IO.File.Exists(address))
                {
                    System.IO.File.Delete(address);
                }

                System.Xml.XmlTextWriter writer =
                    new System.Xml.XmlTextWriter(address, Encoding.GetEncoding("GBK"));
                writer.Formatting = System.Xml.Formatting.Indented;

                //XML文档创建开始
                writer.WriteStartDocument();

                writer.WriteComment("DataTable: " + dt.TableName);

                writer.WriteStartElement("DataTable"); //DataTable开始

                writer.WriteAttributeString("TableName", dt.TableName);
                writer.WriteAttributeString("CountOfRows", dt.Rows.Count.ToString());
                writer.WriteAttributeString("CountOfColumns", dt.Columns.Count.ToString());

                writer.WriteStartElement("ClomunName", ""); //ColumnName开始

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    writer.WriteAttributeString(
                        "Column" + i.ToString(), dt.Columns[i].ColumnName);
                }

                writer.WriteEndElement(); //ColumnName结束

                //按行各行
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    writer.WriteStartElement("Row" + j.ToString(), "");

                    //打印各列
                    for (int k = 0; k < dt.Columns.Count; k++)
                    {
                        writer.WriteAttributeString(
                            "Column" + k.ToString(), dt.Rows[j][k].ToString());
                    }

                    writer.WriteEndElement();
                }

                writer.WriteEndElement(); //DataTable结束

                writer.WriteEndDocument();
                writer.Close();

                //XML文档创建结束
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }

            return(true);
        }