Options to generate XML data from tabular data

Hi!
We have a functional requirement to implement an XML-generation from tabular data, in .NET.
Non-functional requirements are that the schema of the XML-document, and the mapping between the fields in the tabular data and the elements/attributes must be “as dynamic as possible”, without having too much effect on the performance.

For instance, consider the following tabular data (this is very simplified, just to show the point):
Table “Model”
ModelName      Manufacturer
V70      Volvo
XC60      Volvo
Clio      Renault
Espace      Renault

Table “Car”
ModelName      Year      Color
V70      2009      Red
V70      2008      Black
XC60      2003      Silver
Clio      2001      Red
Espace      2002      Grey
Espace      2003      Black

This could generate the following XML-document:
<Models>
      <Model name="V70" manufacturer="Volvo">
            <Cars>
                  <Car year="2009" color="Red"/>
                  <Car year="2008" color="Black"/>
            </Cars>
      </Model>
      <Model name="XC60" manufacturer="Volvo">
            <Cars>
                  <Car year="2003" color="Silver"/>
            </Cars>
      </Model>
      ...      
</Models>

However, it could also be:

<Colors>
      <Color name="Red">
            <Cars>
                  <Car modelName ="V70" manufacturer = "Volvo" year = "2009" />
                  <Car modelName ="Clio" manufacturer = "Renault" year = "2001" />
            </Cars>
      </Color>
      <Color name="Black">
            <Cars>
                  <Car modelName ="V70" manufacturer = "Volvo" year = "2008" />
                  <Car modelName ="Espace" manufacturer = "Renault" year = "2003" />
            </Cars>
      </Color>
       ...
</Colors>

If the schema was fixed (say, the first example above), it would be easy to implement this using a traditional technique (using LinqToSql+LingToXml, for instance), thus “hard-coding” the schema into the code.

The performance would be good. However, it requires changing the code + recompiling + distributing the new DLL if the schema changes in the future.

A more dynamic approach would probably be to use XSLT-templates. Then, when the schema needs to be changed, the XSLT-template is “simply” modified according to the new schema, and this is then distributed.
Performance, however, would be worse as when using a more “hard-coded” technique.

Now, to my questions:
1.      I have a feeling I am missing something an option here. If I have the XSD-schema, and the mapping between the elements in the schema and the tabular data, shouldn’t there be a really easy way to generate the XML data?
2.      What would be my best option? I know there may be many answers to this, but please give me your ideas.

Thanks!
/Fredrik

gunman69Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I don't have a specific answer, but I am willing to explore this question more deeply to find a better answer.

I have heard about LINQ-to-XSD, which brings with it LINQTOXML.EXE, an upgraded version of XSD.EXE.  The backing store is an XDocument, where you can use LINQ queries to pull data.

LINQ to Everything - LINQ to XSD adds more LINQiness
http://www.hanselman.com/blog/LINQToEverythingLINQToXSDAddsMoreLINQiness.aspx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.