I have an application that imports information from a CSV file or from a database and exports it to XML. This XML is currently being persisted to a file. However due to project needs I have decided it may be better to persist this XML to a database.
Currently I have CSV, XML and SQL repositories that deal with importing/exporting data. The XML repository persists the passed in object to a file. It currently is where the mapping of the object to XML is stored, hence it is the only place that knows about this structure (likewise, the other repositories for their respective structures).
Now that I want to store the XML in the database I am beginning to question this architecture. In order to do an insert into the database, the structure of the XML must be accessible from the SQL repository (n.b. data in other columns can be inserted into the DB along with the XML). This leads me to wonder if the XML representation should be stored in the object itself, or in a service layer or somewhere else.
What are the best ways to implement a solution to this problem?
UPDATE: A clarification to my question. The XML repository currently persists to a file. It seems to me that this is the wrong level to keep the knowledge of the structure of the XML at, as then I don't have flexibility in persisting the XML representation to whatever medium I desire. Is it poor design to let the object have knowledge of it's XML representation (or CSV representation, etc)? Should the knowledge of that structure be kept at another level, and what level would that be?