Search code examples
c#xmlwcfxelement

Update xml where structure is unknown and different for each record


I need to update some xml where the structure is unknown, and I'm not quite sure where to begin. I have a field with some xml in a database table, and this can be different xml for each record. The associated schema is also stored in the database.

I'm creating a web service where the updates are being sent as an XElement. I need to find the correct nodes and update them (any number of nodes could be sent in the update). I've got a separate method to handle adding of new nodes as I can just merge XDocuments to do that.

Any pointers on where to start?

Thanks,

Annelie


Solution

  • You are going to have to come up with a structure that can understand what you are sending.

    One idea is, in the incoming root node have a Path Attribute that will point to the path in the receiving xml document that is the place for the incoming node(s).

    Two, or have a separate call to the service that only ever receives one type of response and therefore knows what to do with the response. A separate call for each of the different response types.

    So either know what you are sending/receiving, or embed in the incoming xml how to handle it.

    Edit As your title says, you don't know the structure, you are still going to have to have some way of understanding (aka structure) or you can't possibly know where to store the incoming data.