Go | New | Find | Notify | Tools | Reply |
Member |
It's spaces and vi is better than emacs. Beagle lives matter. ______ (\ / @\_____ / ( ) /O / ( )______/ ///_____/ | |||
|
Member |
OP updated to include XML now. Got into out former dev's machine & see that the current [stalled] project's code is XML not C#. The Enemy's gate is down. | |||
|
Baroque Bloke |
Re: vi is better than emacs My opinion differs. Among other things, emacs is aware of your revision control system, so code revisions can be checked-in/out without leaving the editor. Very handy. Serious about crackers | |||
|
Down the Rabbit Hole |
Learning to read, write and manipulate .xml files is extremely useful in the business world. The learning videos on the Microsoft site with take you a long way. Here is a short example of using C# to read .xml files to give you an idea of what it looks like. Visual Studio and C# have all the tools you'll ever need. This example reads the needed .xml data, inserts each record into a DataRecord and inserts the data into a SQL database table. There are a number of ways to do the same exact thing. This is just one of them. Some of the field names have been changed to protect the innocent. using System; using System.IO; using System.Linq; using System.Xml; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace MoveXMLFiles { class Program { [Obsolete] static void Main(string[] args) { string path = "U:\\Sigforum\\Inventory"; var result = Directory.EnumerateFiles(path, "*.xml", SearchOption.AllDirectories).Union(Directory.EnumerateFiles(path, "*.xml", SearchOption.AllDirectories)); foreach (var file in result) { // Console.WriteLine(file); // DeleteSQLRecords(); XDocument doc = new XDocument(); XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Section"); DataSet ds = new DataSet(); DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("PUBNAME1", typeof(string))); dt.Columns.Add(new DataColumn("TITLEDESCR1", typeof(string))); dt.Columns.Add(new DataColumn("TITLECODE1", typeof(string))); dt.Columns.Add(new DataColumn("ATTRIBUTE011", typeof(string))); dt.Columns.Add(new DataColumn("JOBDESCR1", typeof(string))); dt.Columns.Add(new DataColumn("INSERTCODE1", typeof(string))); dt.Columns.Add(new DataColumn("INVDATE1", typeof(string))); dt.Columns.Add(new DataColumn("LASTACTIVITY1", typeof(string))); dt.Columns.Add(new DataColumn("CSRNAME1", typeof(string))); dt.Columns.Add(new DataColumn("ACTUALQTY1", typeof(string))); dt.Columns.Add(new DataColumn("SKU1", typeof(string))); dt.Columns.Add(new DataColumn("LOC1", typeof(string))); dt.Columns.Add(new DataColumn("ATTRIBUTE051", typeof(string))); dt.Columns.Add(new DataColumn("FORM1", typeof(string))); dt.Columns.Add(new DataColumn("PHYSCONTID1", typeof(string))); dt.Columns.Add(new DataColumn("CONTGROSSWGT1", typeof(string))); dt.Columns.Add(new DataColumn("Division", typeof(string))); dt.Columns.Add(new DataColumn("FlatFileName", typeof(string))); dt.Columns.Add(new DataColumn("CreateDate", typeof(string))); int counter = 0; for (i = 0; i <= xmlnode.Count - 1; i++) { DataRow dr = dt.NewRow(); if (xmlnode[i].ChildNodes.Item(0) != null) { dr["PUBNAME1"] = xmlnode[i].ChildNodes.Item(0).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(1) != null) { dr["TITLEDESCR1"] = xmlnode[i].ChildNodes.Item(1).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(2) != null) { dr["TITLECODE1"] = xmlnode[i].ChildNodes.Item(2).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(3) != null) { dr["ATTRIBUTE011"] = xmlnode[i].ChildNodes.Item(3).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(4) != null) { dr["JOBDESCR1"] = xmlnode[i].ChildNodes.Item(4).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(5) != null) { dr["INSERTCODE1"] = xmlnode[i].ChildNodes.Item(5).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(6) != null) { dr["INVDATE1"] = xmlnode[i].ChildNodes.Item(6).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(7) != null) { dr["LASTACTIVITY1"] = xmlnode[i].ChildNodes.Item(7).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(8) != null) { dr["CSRNAME1"] = xmlnode[i].ChildNodes.Item(8).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(9) != null) { string strTemp = xmlnode[i].ChildNodes.Item(9).FirstChild.InnerText; strTemp.Replace(",", ""); dr["ACTUALQTY1"] = strTemp; } if (xmlnode[i].ChildNodes.Item(10) != null) { dr["SKU1"] = xmlnode[i].ChildNodes.Item(10).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(11) != null) { dr["LOC1"] = xmlnode[i].ChildNodes.Item(11).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(12) != null) { dr["ATTRIBUTE051"] = xmlnode[i].ChildNodes.Item(12).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(13) != null) { dr["FORM1"] = xmlnode[i].ChildNodes.Item(13).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(14) != null) { dr["PHYSCONTID1"] = xmlnode[i].ChildNodes.Item(14).FirstChild.InnerText; } if (xmlnode[i].ChildNodes.Item(15) != null) { decimal j = 0; bool boolresult = decimal.TryParse(xmlnode[i].ChildNodes.Item(15).FirstChild.InnerText, out j); if (boolresult == true) { dr["CONTGROSSWGT1"] = xmlnode[i].ChildNodes.Item(15).FirstChild.InnerText; } } else { dr["CONTGROSSWGT1"] = "0.00"; } string[] strSplit = path.ToString().Split(null); dr["Division"] = strSplit[strSplit.Length - 1]; dr["FlatFileName"] = path; dr["CreateDate"] = DateTime.Now.ToString(); dt.Rows.Add(dr); counter++; } ds.Tables.Add(dt); string connectionString = "Data Source=SQL001;Initial Catalog=TestDatabase;Integrated Security=True"; using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection)) { connection.Open(); bulkCopy.DestinationTableName = "SQLTable "; bulkCopy.WriteToServer(dt); } } } } } Diligentia, Vis, Celeritas "People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf." -- George Orwell | |||
|
Optimistic Cynic |
I've used GNU Emacs for decades as my preferred editor, I still use it occasionally. But these days, for perhaps 95% of my editing I use some variant of vi. I will evaluate what operations I will likely have to perform before selecting the editor I will use, for example, if I expect to have to do a lot of paragraph reformatting or column manipulation, emacs gets the nod. Vi is generally more comfortable when passing text to an external program, such as awk, sed, etc., something I do a lot. I do find myself attempting to use emacs or vi commands in a visual editor, like the one I'm typing this in on SF. If I am writing a lengthy text, I'll do it in a "real" editor, then paste into the browser buffer. Sure wish "emacs mode" (or "vi mode") were an option in browsers like they are in some GUI editors! Overall, I'd keep vi if I could only have one. | |||
|
Down the Rabbit Hole |
All this talk about Vi brings back an old memory from the 1990s. Our Solaris administrator left a root command prompt unattended for a few minutes so I used the opportunity to make a copy of Vi in my home directory. I then changed the permissions of the file. From that point on, whenever I logged in with my login, I could launch the copy of Vi in my directory. Once launched, I could shell out and have a ADMIN command prompt. Useful for moving my files ahead of everyone else's in the queue. Sorry for the thread drift, P250UA5. Diligentia, Vis, Celeritas "People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf." -- George Orwell | |||
|
Member |
Jupiter, I'll have to look at that when I have something bigger than a phone screen. The Enemy's gate is down. | |||
|
Down the Rabbit Hole |
NP. I should have removed some of the fields to make it shorter and cleaner. Diligentia, Vis, Celeritas "People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf." -- George Orwell | |||
|
Powered by Social Strata | Page 1 2 |
Please Wait. Your request is being processed... |