Reading the node body

Hello!

I have dealt with the previous problem. The problem was I haven't actually added those objects as the children of the GoLabeledLink, so it has worked incorrectly. Thanks for mentioning that.
Now, concerning our project, we are defining the layout of the data in each of our file types. We were thinking of putting some node's attributes as it's child elements for the better readability and easier understanding. I was wondering if there was a way of reading other XML elements that would be inserted as node's children. So they would probably be mixed with the elements defining ports, but wouldn't have anything to do with the Go libraries. I've been reading the manual about it and I'm pretty sure I have to do something with the consumeBody() function. Could you please advise the best way to do this? Thanks.

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.

Then your node class's transformer's ConsumeChild method will be called, and you can figure out what you want to do with your data. (ConsumeChild will be called if you had set GoXmlTransformer.BodyConsumesChildElements to true.)

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.