SIGforum.com    Main Page  Hop To Forum Categories  The Lounge    Learning C#/XML ?
Page 1 2 
Go
New
Find
Notify
Tools
Reply
  
Learning C#/XML ? Login/Join 
Member
posted Hide Post
It's spaces and vi is better than emacs.


Beagle lives matter.
______
(\ / @\_____
/ ( ) /O
/ ( )______/
///_____/
 
Posts: 908 | Location: Panhandle of Florida | Registered: July 23, 2008Reply With QuoteReport This Post
Member
Picture of P250UA5
posted Hide Post
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.
 
Posts: 16344 | Location: Spring, TX | Registered: July 11, 2011Reply With QuoteReport This Post
Baroque Bloke
Picture of Pipe Smoker
posted Hide Post
quote:
Originally posted by xd45man:
Its spaces and vi is better than emacs.


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
 
Posts: 9726 | Location: San Diego | Registered: July 26, 2014Reply With QuoteReport This Post
Down the Rabbit Hole
Picture of Jupiter
posted Hide Post
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. Smile


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

 
Posts: 4980 | Location: North Mississippi | Registered: August 09, 2002Reply With QuoteReport This Post
Optimistic Cynic
Picture of architect
posted Hide Post
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.
 
Posts: 6975 | Location: NoVA | Registered: July 22, 2009Reply With QuoteReport This Post
Down the Rabbit Hole
Picture of Jupiter
posted Hide Post
quote:
Originally posted by architect:


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.


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. Razz

Sorry for the thread drift, P250UA5. Smile


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

 
Posts: 4980 | Location: North Mississippi | Registered: August 09, 2002Reply With QuoteReport This Post
Member
Picture of P250UA5
posted Hide Post
Jupiter, I'll have to look at that when I have something bigger than a phone screen.




The Enemy's gate is down.
 
Posts: 16344 | Location: Spring, TX | Registered: July 11, 2011Reply With QuoteReport This Post
Down the Rabbit Hole
Picture of Jupiter
posted Hide Post
quote:
Originally posted by P250UA5:
Jupiter, I'll have to look at that when I have something bigger than a phone screen.


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

 
Posts: 4980 | Location: North Mississippi | Registered: August 09, 2002Reply With QuoteReport This Post
  Powered by Social Strata Page 1 2  
 

SIGforum.com    Main Page  Hop To Forum Categories  The Lounge    Learning C#/XML ?

© SIGforum 2024