Hello all,
for some time now I have been trying to solve the following problem and I'm starting to run out of ideas:
I have generated a set of C# classes from an xsd schema using the xsd.exe tool and deserializing xml files works fine. The problem is that apart from the convenience and safety of using the auto generated classes, I also need information about the xml hierarchy, ie I need to establish parent-child relationships between the objects created during deserialization. Note that I want to avoid keeping a separate xml hierarchy structure (like a DOM tree), but rather make the generated objects keep track of their parents and children.
I have managed to pull this off in java using JAXB by:
Defining a common base class for all deserialized objects. This base class contains a list of children and a reference to a parent object (if any).
Using the Unmarshaller.Listener functionality that provides a callback on completed object deserialization. This callback provides a reference to the parent of the recently deserialized object, which makes establishing parent-child relationships trivial.
How would I go about doing this in C#? I have had a look at the MSDN docs and done quite a lot of googling, but haven't been able to find any useful information.
Any help would be much appreciated.
/K