Hello!
If you already have a class defined to represent that data in memory, you can just define a transformer for that class. That way when the reader sees those nested XML elements, it will create an instance of your data class and initialize/load it with the information in that XML element according to how you define that data transformer.
This method works very nice. But I have one issue. As those extra elemets are really simmilar to each other, I’ve decided to use one class for all of those elements. I also have a property in it which holds the name of the particular parsed element (XmlTransformer.ElementName), so I could use a switch statement later on in the node’s ConsumeChild method to decide what data goes where. The problem occures when loading because I have defined the same TransformerType for all such XML elements. It parses only the last Transformer added to the reader. When I make a new class, which derives from this one (I change nothing else, even the base constructor is called, just the name of the class is different) and it starts working. As I wouldn’t like to write such derived classes just to change their names for each different element, I’m asking if there is a way to use more transformers with the same TransformerType at the same time. Thanks.
You can have one GoXmlTransformer defined for multiple Types. You’ll need to make sure each method can handle all of the classes, by switching on the Type of the object and casting correspondingly.
For reading, you’ll need to override Allocate to decide which class to instantiate.