473,842 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's the best way to validate a CSV file

Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for instance
for "05/07/1976" ,I need to make sure that it's in the right format ,It's
not later than today and lots of other rules ,Is there somebody who can help
me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R
Nov 16 '05 #1
7 16291
Couple of ways.

String.Split to seperate parts of it, and regex validate it.

Or

string.replace commas for some xml tag, prepend it one additional tag, and
then validate against a schema.

There might be better ways of doing it though.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft. com> wrote in message
news:uj******** ******@TK2MSFTN GP15.phx.gbl...
Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for instance for "05/07/1976" ,I need to make sure that it's in the right format ,It's
not later than today and lots of other rules ,Is there somebody who can help me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R

Nov 16 '05 #2
Ali,

In the same way as it was done forever, even when it was on paper or stone.

Just read them one by one, and test every object in it against the rules
that are for that.

Why would that have changed?

Cor
Nov 16 '05 #3
Hi Sahil,

We came across eachother again( do you remember the hot issue on Datareader
and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
String.Split to seperate parts of it, and regex validate it. Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl... Couple of ways.

String.Split to seperate parts of it, and regex validate it.

Or

string.replace commas for some xml tag, prepend it one additional tag, and
then validate against a schema.

There might be better ways of doing it though.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft. com> wrote in message
news:uj******** ******@TK2MSFTN GP15.phx.gbl...
Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for

instance
for "05/07/1976" ,I need to make sure that it's in the right format
,It's
not later than today and lots of other rules ,Is there somebody who can

help
me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R


Nov 16 '05 #4
Yes I remember you Ali :) Nice to run into you again.

You might want to check this out -
http://msdn.microsoft.com/XML/XMLCod...lcsvreader.asp

Regex is under System.Text.Reg ularExpressions - it is used for text matching
based on a pattern. It's pretty awesome once you get used to it.
--

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft. com> wrote in message
news:#0******** ******@TK2MSFTN GP14.phx.gbl...
Hi Sahil,

We came across eachother again( do you remember the hot issue on Datareader and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
String.Split to seperate parts of it, and regex validate it.

Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl...
Couple of ways.

String.Split to seperate parts of it, and regex validate it.

Or

string.replace commas for some xml tag, prepend it one additional tag, and then validate against a schema.

There might be better ways of doing it though.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft. com> wrote in message
news:uj******** ******@TK2MSFTN GP15.phx.gbl...
Hi all,
I am getting a CSV file like this from our client:

"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........

I need to validate **each filed value** against a set of rules ,for

instance
for "05/07/1976" ,I need to make sure that it's in the right format
,It's
not later than today and lots of other rules ,Is there somebody who can

help
me how to that?Can I map it to some sort of xml schema or something?

Thanks for your help.

Ali-R



Nov 16 '05 #5
You actual presented two solutions:
> String.Split to seperate parts of it, and regex validate it.
> Or
> string.replace commas for some xml tag, prepend it one additional
> tag,and then validate against a schema.

System.Text.Reg ularExpressions is used for the first one and the link you
sent me is for the second one,right? (just checking)

I will send you my other questions as soon as I make sure I was right...

Thanks sohil,like always your solutions are unique;-)

Ali-R

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:Oe******** ******@TK2MSFTN GP12.phx.gbl...
Yes I remember you Ali :) Nice to run into you again.

You might want to check this out -
http://msdn.microsoft.com/XML/XMLCod...lcsvreader.asp

Regex is under System.Text.Reg ularExpressions - it is used for text
matching
based on a pattern. It's pretty awesome once you get used to it.
--

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft. com> wrote in message
news:#0******** ******@TK2MSFTN GP14.phx.gbl...
Hi Sahil,

We came across eachother again( do you remember the hot issue on

Datareader
and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
> String.Split to seperate parts of it, and regex validate it.

Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl...
> Couple of ways.
>
> String.Split to seperate parts of it, and regex validate it.
>
> Or
>
> string.replace commas for some xml tag, prepend it one additional tag,

and > then validate against a schema.
>
> There might be better ways of doing it though.
>
> - Sahil Malik
> http://codebetter.com/blogs/sahil.malik/
>
>
>
> "Ali-R" <Al**@microsft. com> wrote in message
> news:uj******** ******@TK2MSFTN GP15.phx.gbl...
>> Hi all,
>> I am getting a CSV file like this from our client:
>>
>> "C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
>>
>> I need to validate **each filed value** against a set of rules ,for
> instance
>> for "05/07/1976" ,I need to make sure that it's in the right format
>> ,It's
>> not later than today and lots of other rules ,Is there somebody who
>> can
> help
>> me how to that?Can I map it to some sort of xml schema or something?
>>
>> Thanks for your help.
>>
>> Ali-R
>>
>>
>
>



Nov 16 '05 #6
Sahil,

The problem with String.split is that in my CSV file I'm using this format:

"fieldvalue1"," fieldValue2",.. ... (I mean there is a double qoute around
each filed value) can it parse sucha CSV file?

I think I have to use a custom impelmentation to seperate CSV field Values
into an array list and then use regx t validate it ,right?

thanks
"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:Oe******** ******@TK2MSFTN GP12.phx.gbl...
Yes I remember you Ali :) Nice to run into you again.

You might want to check this out -
http://msdn.microsoft.com/XML/XMLCod...lcsvreader.asp

Regex is under System.Text.Reg ularExpressions - it is used for text
matching
based on a pattern. It's pretty awesome once you get used to it.
--

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Ali-R" <Al**@microsft. com> wrote in message
news:#0******** ******@TK2MSFTN GP14.phx.gbl...
Hi Sahil,

We came across eachother again( do you remember the hot issue on

Datareader
and Dataset in ado.net group-Disconnected vs connected approach)

Anyways,You say that
> String.Split to seperate parts of it, and regex validate it.

Imagine that I have split the CSV file into an ArrayList ,,How can I use
regex to validate it
? what's regex?

Thanks

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl...
> Couple of ways.
>
> String.Split to seperate parts of it, and regex validate it.
>
> Or
>
> string.replace commas for some xml tag, prepend it one additional tag, and > then validate against a schema.
>
> There might be better ways of doing it though.
>
> - Sahil Malik
> http://codebetter.com/blogs/sahil.malik/
>
>
>
> "Ali-R" <Al**@microsft. com> wrote in message
> news:uj******** ******@TK2MSFTN GP15.phx.gbl...
>> Hi all,
>> I am getting a CSV file like this from our client:
>>
>> "C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
>>
>> I need to validate **each filed value** against a set of rules ,for
> instance
>> for "05/07/1976" ,I need to make sure that it's in the right format
>> ,It's
>> not later than today and lots of other rules ,Is there somebody who
>> can
> help
>> me how to that?Can I map it to some sort of xml schema or something?
>>
>> Thanks for your help.
>>
>> Ali-R
>>
>>
>
>



Nov 16 '05 #7
How do you define the rules?

Thanks
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:ON******** ********@TK2MSF TNGP14.phx.gbl. ..
Ali,

In the same way as it was done forever, even when it was on paper or
stone.

Just read them one by one, and test every object in it against the rules
that are for that.

Why would that have changed?

Cor

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1298
by: Brian van den Broek | last post by:
Hi all, I'm just starting to employ unit testing (I'm using doctest), and I am uncertain how to handle writing tests where the behaviour being tested is dependant on whether certain file paths point to actual files. I have a class which takes, in its __init__, a list of file paths to process. The class has a method to validate that the paths passed in are appropriate ones for the class. One portion of the validation code ensures that...
39
2926
by: Holly | last post by:
I'm trying to validate my code and I can't figure out what kind of doctype I have. The validator can't tell me anything because it can't move beyond the doctype declaration. http://www.wavian.com/clients/pugwash/ Is there anyway to tell what kind of doctype this is? I tried inserting a few different types (please excuse me if this is the stupid way to do it, I am learning...) but am unsuccessful.
8
3110
by: Dean Speir | last post by:
Hi... I've been referred to this Newsgroup by the W3C Markup Validator FAQ. I've been happily using this Validator <http://validator.w3.org> for the past 18 months with great success, but suddenly I cannot get it to "read" my HTML documents by the "Validate by File Upload" method. It keeps giving me the following message: Sorry, I am unable to validate this document
9
2234
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see) in page_load, or elsewhere, that says page.validate, no control says "causesvalidation=true", and the AutoEventWireup is set to false. So I would think that the control's server event function would NOT execute, but it does execute right after...
10
1999
by: Mike Logan | last post by:
I am using the "contract first" design methodology. Contract First is design the WSDL first then design the server and client. However I must design my XSD/XML Schema before anything. I am developing my schema now. I have a version on my schema. However once I start the server side code, how is the server now that the right "complexType" is being passed? What happens if this complexType my web service consumes needs to be...
1
1356
by: KMZ_state | last post by:
We have a debate here. We are receiving a CSV file specified by the user and need to validate the contents, writing the "good" records to the database and displaying the "bad" records to the user. One developer wants to loop through the CSV file right on the web layer (ASPX) and then only pass the "good" records onto the DAL. The other developer wants to pass the whole file as an OBJECT to the business logic layer and then loop through...
1
1529
by: thomas.porschberg | last post by:
Hi XML-gurus, imagine a provider of some information in XML format and a client who reads this data. Both sides share a XSD as a contract. I think this is quite common. Now the client wants to validate the XML data. Unfortunatly the provider of the XML data is not able to offer XSD access at a webserver
5
2755
by: Ryan Liu | last post by:
I have an application need export ane import data of projects. There are about 10 database tables releated to one project. 3 of them each could have up to 100K lines data. I can export all data out into a xml file and then zip it. When I do import, I parse this xml file and then insert into database myself. Or I can export all tables out in csv format and then use mysql's client command "load local file" (which is claimed very fast...
6
2757
by: Jonny | last post by:
Hi, I'm trying to validate my xml against a xsd but I can't get it to work. Originally, I wanted to validate an xml string but since I didn't get that to work I tried to validate an xml file instead. Didn't work either. Actuallty, the xml gets loaded but there are no events raised that says my xml is incorrect! I'm using .NET 2.0 and my code is listed below. ALL help is appreciated! Thanks!
0
9872
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10612
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10314
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5696
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.