473,378 Members | 1,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

data from CSV + Rules XSD -> XML

Ash
I am writing a C# program to to convert CSV to XML based on an XSD schema file.

I have a CSV that could contain 3 different types of lines that is
identified by the first field of data Assume that the 3 types are A,B,C

A,foo,bar,1,2
B,barr,4,5
C,foox,1
A,bar,foo,1,2,3
....

So a message that starts with
A ...has.... 5 fields
B ...has.... 4 fields
C ...has.... 3 fields

My XSD would be something like

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="BLAA" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:group name="A">
<xs:sequence>
<xs:element name="colA1" type="xs:string" />
<xs:element name="colA2" type="xs:string" />
<xs:element name="colA3" type="xs:int" />
<xs:element name="colA4" type="xs:int" />
</xs:sequence>
</xs:group>
<xs:group name="B">
<xs:sequence>
<xs:element name="colB1" type="xs:string" />
<xs:element name="colB2" type="xs:int" />
<xs:element name="colB3" type="xs:int" />
</xs:sequence>
</xs:group>
<xs:group name="C">
<xs:sequence>
<xs:element name="colC1" type="xs:string" />
<xs:element name="colC2" type="xs:int" />
</xs:sequence>
</xs:group>
</xs:schema>

Final XML output would be somthing like
<data>
<ROW type="A">
<colA1>foo</colA1>
<colA2>bar</colA2>
<colA3>1</colA3>
<colA4>2</colA4>
</ROW>
<ROW type="B">
<colB1>barr</colB1>
<colB2>4</colB2>
<colB3>5</colB3>
</ROW>
<ROW type="C">
<colC1>foox</colC1>
<colC2>1</colC2>
</ROW>
......

</data>

Of course my C# will know that when you read the CSV and find the first word
to be A is to go to look for the A "type" in the XSD and know the following
sequence.
in http://www.creativyst.com/Prod/15/ they are optaining the
COL[A|B|C][1..n] from a form input. I want to load it from an XSD.
My question i guess finally would be
- Since I will parse the data based on an XSD, Is there a specific API for
reading XSD or just use XPath as if i am reading a normal XML? None of the
classes in System.Xml.Xsl seemed to do that sort of parsing.
-Any body with a better idea out there?? :)

Thanks aloT!!!
Nov 17 '05 #1
1 2183
Ash
I just found out about System.Xml.Schema.
Thanks!

Nov 17 '05 #2

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

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
10
by: Luca | last post by:
Hello, have a problem with this XML, I need XSLT to filter the products list based on rules writes in RULE tag. I need copy only CAT and PROD data in PRODUCTS-LIST that match CAT and PROD...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
18
by: Damodar Periwal | last post by:
-------------------------------------------------------------- Software Tree Revs Up JDX OR-Mapper With Innovative And High-Performance Features...
41
by: laimis | last post by:
Hey guys, I just recently got introduced to data mappers (DTO mapper). So now I have a SqlHelper being used by DTOMapper and then business layer is using DTOMapper when it needs to persist...
1
by: Diane Yocom | last post by:
I'm still very new to ASP.Net, so wanted to get some advice on how to solve the following design problem (sorry my explanation is so long): I'm developing an ASP.Net intranet app (using VB.Net...
2
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to...
18
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
0
by: Christoph Haas | last post by:
Hi, list... I have written an application in Perl some time ago (I was young and needed the money) that parses multiple large text files containing nested data structures and allows the user to...
4
by: Basilisk96 | last post by:
This topic is difficult to describe in one subject sentence... Has anyone come across the application of the simple statement "if (object1's attributes meet some conditions) then (set object2's...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.