Turn Csv File Into Xml Validator

  1. Xml Validator
  2. Python Read Csv File Into Array
Active1 year, 2 months ago

Are there any good sites/services to validate consistency of CSV file ?

The open source CSV Validator application and API, offers both CSV Schema parsing and CSV file. Note, the CSV Schema. This project contains an API that you can use to convert XML into comma separated values (CSV). You can copy and paste the CSV data into the input box and click the Submit button, or click the Open File button to select a file from your file system. Now XML Validator Buddy 4.6 also supports to convert CSV input to XML or JSON. This means you can also export your spreadsheet data from Excel to a CSV file and generate XML or JSON from it using XML Validator Buddy. XML/JSON editor, batch validator, Schematron and JSON/XML/CSV conversions in one tool. Convert XML to CSV. Use FME to convert data from XML schema to the CSV tabular format. Start Free Trial. Create workflows that convert data from XML to CSV – no coding required. FME’s tools allow you to manipulate the structure and contents of complex XML datasets into a CSV file that suits your exact requirements.

The same as W3C validator but for CSV?

Ambo100
4952 gold badges12 silver badges26 bronze badges
Dmitriy NaumovDmitriy Naumov
2,8114 gold badges17 silver badges44 bronze badges

5 Answers

I recently came across Google Refine - it's not a service for validating CSV files, it's a tool you download locally, but it does provide a lot of tools for working with data and detecting anomalies.

As mentioned in a reply, 'CSV' has become an ill-defined term, principally because people don't follow the One True Way when using delimiter separated data

EDIT/UPDATE (2016-08-09):
CSV Currently Becoming a Well-Defined Term by the W3C CSV Working Group

albert
7,4833 gold badges37 silver badges57 bronze badges
AdrianAdrian

The Open Data Institute is developing a CSV validation service that will allow users to check the structure of their data as well as validate it against a simple schema.

The service is still very much in alpha but can be found here:

The code for the application and the underlying library are both open source:

The README in the library provides a summary of the errors and warnings that can be generated. The following types of error can be reported:

  • :wrong_content_type -- content type is not text/csv
  • :ragged_rows -- row has a different number of columns (than the first row in the file)
  • :blank_rows -- completely empty row, e.g. blank line or a line where all column values are empty
  • :invalid_encoding -- encoding error when parsing row, e.g. because of invalid characters
  • :not_found -- HTTP 404 error when retrieving the data
  • :quoting -- problem with quoting, e.g. missing or stray quote, unclosed quoted field
  • :whitespace -- a quoted column has leading or trailing whitespace

The following types of warning can be reported:

  • :no_encoding -- the Content-Type header returned in the HTTP request does not have a charset parameter
  • :encoding -- the character set is not UTF-8
  • :no_content_type -- file is being served without a Content-Type header
  • :excel -- no Content-Type header and the file extension is .xls
  • :check_options -- CSV file appears to contain only a single column
  • :inconsistent_values -- inconsistent values in the same column. Reported if <90% of values seem to have same data type (either numeric or alphanumeric including punctuation)
ldoddsldodds

The National Archives developed a CSV Schema Language and CSV Validator, software written in Java. It's open source.

MilosMilos

To validate a CSV file I use the RAINBOW CSV extension in Visual Studio Code and also I open the CSV file in Excel.

mruanovamruanova
2,3852 gold badges16 silver badges38 bronze badges

CSV Lint at csvlint.com (not .io :) is a service we're building to solve this problem. It checks CSV files against user-defined validation rules / schemas cell by cell.

We spent a lot of time tweaking the UI to allow users to create complex validation rules / schemas easily that meet their business needs without a single line of code.

Our offline validation feature allows users to see the results in-realtime even when validating multiple large size (with millions+ rows) files, and most importantly it 100% protects user data privacy.

JoeJoe

protected by Ry-Jun 4 '13 at 23:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged validationservicecsvweb or ask your own question.

[Update: As Paul Owen notes in the comments to this post, there were issues with the markup as presented in the post. I removed the formatting and replaced the XSLT to clarify the stylesheet.]

Mencari ayat dalam bibel bahasa batak toba. In the SQLXML group on Yahoo! groups, Jonathan Smith asks:

I’m trying to find a way to convert a .csv file to xml using stylesheets and I can’t seem to find anything. I did read about something called fxml or something like that for flat files but I don’t think it’s a standard. Can anyone help me in this regard?

This is certainly doable with XSLT, provided that the data contains characters allowable in XML. If not, you will have some data scrubbing and character escaping to do to represent the same data as XML. In the simple case of “<” characters, this is easily done with character code escapes like &lt;. For high-order values, this is going to require some other scrubbing and character replacement because XSLT cannot transform the data even with character entity references for the characters in unacceptable ranges.

The first order of business is to put a root tag on the data. This will allow us to load the data into a DOM and ensure that the data can be represented as XML.

Import csv file into google contacts
<root>1,5 main st, ,Cumming, GA, 30040,Kirk Evans
2,13 elm st, ,Anywhere, NJ, 07825,Bob Smith</root>

Once we have an XML document where all of the data is well-formed, we next need to start the transformation process. Logically, we can break the problem into 2 steps. We need to get the rows of data, and then break each row up by its individual fields.

The XPath string function substring-before() can be used to grab all of the data before the first carriage return. The function substring-after() can then be used to grab all of the data after the first carriage return. We just call the same function recursively until the string we are processing no longer has any carriage returns, at which point we add the remaining string to the result tree.

<!– template that actually does the conversion–>
<xsl:template name =”texttorows” >
<!– import $StringToTransform–>
<xsl:param name =”StringToTransform” select =””” />
<xsl:choose>
<!– string contains linefeed–>
<xsl:when test =”contains($StringToTransform,’&#xA;’)” >
<!– Get everything up to the first carriage return–>
<row>
<xsl:call-template name =”csvtoxml” >
<xsl:with-param name =”StringToTransform” select =”substring-before($StringToTransform,’&#xA;’)” />
</xsl:call-template>
</row>
<!– repeat for the remainder of the original string–>
<xsl:call-template name =”texttorows” >
<xsl:with-param name =”StringToTransform” >
<xsl:value-of select =”substring-after($StringToTransform,’&#xA;’)” />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!– string does not contain newline, so just output it–>
<xsl:otherwise>
<row>
<xsl:call-template name =”csvtoxml” >
<xsl:with-param name =”StringToTransform” select =”$StringToTransform” />
</xsl:call-template>
</row>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

To break up the columns in each row, we go through the same process. Instead of looking for carriage returns, we look for the first comma. We then call ourselves recursively with the rest of the string until the string contains no more commas.

<xsl:template name =”csvtoxml” >
<!– import $StringToTransform–>
<xsl:param name =”StringToTransform” select =””” />
<xsl:choose>
<!– string contains linefeed–>
<xsl:when test =”contains($StringToTransform,’,’)” >
<!– Get everything up to the first carriage return–>
<elem>
<xsl:value-of select =”substring-before($StringToTransform,’,’)” />
</elem>
<!– repeat for the remainder of the original string–>
<xsl:call-template name =”csvtoxml” >
<xsl:with-param name =”StringToTransform” >
<xsl:value-of select =”substring-after($StringToTransform,’,’)” />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!– string does not contain newline, so just output it–>
<xsl:otherwise>
<elem>
<xsl:value-of select =”$StringToTransform” />
</elem>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Now that we have the 2 template rules in place, we form the entire stylesheet together.

Xml Validator

<xsl:stylesheet version =”1.0″ xmlns:xsl =”http://www.w3.org/1999/XSL/Transform” >
<xsl:output method =”html” />
<!– template that matches the root node–>
<xsl:template match =”/” >
<root>
<xsl:call-template name =”texttorows” >
<xsl:with-param name =”StringToTransform” select =”/root” />
</xsl:call-template>
</root>
</xsl:template>
<!– template that actually does the conversion–>
<xsl:template name =”texttorows” >
<!– import $StringToTransform–>
<xsl:param name =”StringToTransform” select =””” />
<xsl:choose>
<!– string contains linefeed–>
<xsl:when test =”contains($StringToTransform,’&#xA;’)” >
<!– Get everything up to the first carriage return–>
<row>
<xsl:call-template name =”csvtoxml” >
<xsl:with-param name =”StringToTransform” select =”substring-before($StringToTransform,’&#xA;’)” />
</xsl:call-template>
</row>
<!– repeat for the remainder of the original string–>
<xsl:call-template name =”texttorows” >
<xsl:with-param name =”StringToTransform” >
<xsl:value-of select =”substring-after($StringToTransform,’&#xA;’)” />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!– string does not contain newline, so just output it–>
<xsl:otherwise>
<row>
<xsl:call-template name =”csvtoxml” >
<xsl:with-param name =”StringToTransform” select =”$StringToTransform” />
</xsl:call-template>
</row>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name =”csvtoxml” >
<!– import $StringToTransform–>
<xsl:param name =”StringToTransform” select =””” />
<xsl:choose>
<!– string contains linefeed–>
<xsl:when test =”contains($StringToTransform,’,’)” >
<!– Get everything up to the first carriage return–>
<elem>
<xsl:value-of select =”substring-before($StringToTransform,’,’)” />
</elem>
<!– repeat for the remainder of the original string–>
<xsl:call-template name =”csvtoxml” >
<xsl:with-param name =”StringToTransform” >
<xsl:value-of select =”substring-after($StringToTransform,’,’)” />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!– string does not contain newline, so just output it–>
<xsl:otherwise>
<elem>
<xsl:value-of select =”$StringToTransform” />
</elem>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Python Read Csv File Into Array

The result of the transformation is:

</row>
</row>