tags:

views:

19

answers:

1

Using C# I want to be able to map a number of xml feeds to one custom object. Each xml feed has the same kind of data but has its own naming convention.

Ideally i would like to store for each xml feed its own mapping and apply that automatically when copying the xml data to my object. I would like to do this as the system may grow to hundreds of feeds so just being able to store the mappings would make it easier to maintain than writing code for each feed.

So for example, my object consists of

ID, Name

And xml feed one is

Code, ProductName

xml feed two is

UniqueID, FullName

so the mappings would be

ID -> Code Name -> ProductName

and

ID -> UniqueID Name -> FullName

What would be the best way of achieving this?

A: 

I would create a configsection in your config file. You could then have a node for each feed. Then have nodes within that have the mapping information. The nodes in your feed node would match the properties in your c# object and the node value would be the node name in your xml file. You could also even add the full xpath path if it was more complicated.

<feed url="">
    <id>Code</id>
    <Name>ProductName</Name>
</feed>

Then in your app you could load the feed. Then search for the node in your config file to get how to map the fields to your C# object from fields in your xml file.

Just one approach that would make it easy to configure and grow without changing the application unless your c# object changes.

spinon
I like the idea of the config file, how would i go about doing the actual mapping though?
Matt
This should help out.http://msdn.microsoft.com/en-us/library/2tw134k3.aspx
spinon