csv with parent-child columns to xml



Can any of the commercial conversion tools convert csv files
containing "relational" data to xml in an automated fashion? I looked
at the websites for stylussudio and altova, but it looks like I would
have to do some xslt coding for each file. I don't mind filling in
some configuration forms for each project, I just don't want to have
to write code for each one. I have hundreds of these to do over the
next months. I wrote a c# program using an xmldocument, but it
requires a lot of hard coding for each project.

Each csv file has different columns but they all contain some parent-
child relationships. The xml structure for each file would be
different, but in all cases I need to have the child columns be xml
elements nested under xml elements corresponding to the parent
columns. The number of child elements varies. There are some files
with child elements that are also parents of other child elements,
nested many levels deep.

Below is a simple example.

Csv input file:

Department,Division,Firstname,Lastname
IT,Support,Sam ,Smith
IT,Support,Tom ,Jones
IT,Networks,Bill ,Thomas
IT,Networks,John ,English
IT,Networks,Taylor ,Temple
Accounting,Payroll,Sue ,Johnson
Accounting,Payroll,Larry ,Neilson
Accounting,Receivables,Harry ,Feldman
Accounting,Receivables,Stan ,Simon

Xml output file

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<Departments>
<Department>
<DepName>IT</DepName>
<Divisions>
<Division>
<DivisionName>Support</DivisionName>
<Employees>
<Employee>
<FirstName>Sam </FirstName>
<LastName>Smith</LastName>
</Employee>
<Employee>
<FirstName>Tom </FirstName>
<LastName>Jones</LastName>
</Employee>
</Employees>
</Division>
<Division>
<DivisionName>Networks</DivisionName>
<Employees>
<Employee>
<FirstName>Bill </FirstName>
<LastName>Thomas</LastName>
</Employee>
<Employee>
<FirstName>John </FirstName>
<LastName>English</LastName>
</Employee>
<Employee>
<FirstName>Taylor </FirstName>
<LastName>Temple</LastName>
</Employee>
</Employees>
</Division>
</Divisions>
</Department>
<Department>
<DepName>Accounting</DepName>
<Divisions>
<Division>
<DivisionName>Payroll</DivisionName>
<Employees>
<Employee>
<FirstName>Sue </FirstName>
<LastName>Johnson</LastName>
</Employee>
<Employee>
<FirstName>Larry </FirstName>
<LastName>Neilson</LastName>
</Employee>
</Employees>
</Division>
<Division>
<DivisionName>Receivables</DivisionName>
<Employees>
<Employee>
<FirstName>Harry </FirstName>
<LastName>Feldman</LastName>
</Employee>
<Employee>
<FirstName>Stan </FirstName>
<LastName>Simon</LastName>
</Employee>
</Employees>
</Division>
</Divisions>
</Department>
</Departments>
.



Relevant Pages

  • Re: csv with parent-child columns to xml
    ... In the past i've had a lot of success using Altova MapForce, ... The xml structure for each file would be ... The number of child elements varies. ...
    (microsoft.public.dotnet.xml)
  • Re: Help w/Self-Join Hierarchy Query
    ... > EXPLICIT then I may find the answer in there. ... > Then there is the ever popular employee - manager adjacency. ... > FOR XML SELF ...
    (microsoft.public.sqlserver.programming)
  • Stand alone Shredding in SQL Server 2005
    ... what I've read it will have to be some type of bulk processing. ... from the command line or bulk insert from T-SQL. ... the xml I want to shred: ...
    (microsoft.public.sqlserver.xml)
  • Re: Deserialize Business Object
    ... Dim Employee As Employee = CType, ... I am having an issue deserializing a business object from a SQL stored ... As the XML being returned is an XML fragment due to not having a single ... Create a new XmlDocument, add the root element to it, then ...
    (microsoft.public.dotnet.xml)
  • Re: Handling Object Null Reference Errors
    ... Employee e = Something.GetEmployee; ... I coded it to throw an exception if this attribute was NOT found. ... I was like "You said it would always have the xyz attribute". ... We check the Xml. ...
    (microsoft.public.dotnet.framework.aspnet)