Unexpected beheavior of a Transformer

Hi all,

I’m trying to consume some xml and run into some strange behavior.

Some code:

        GoDocument doc = new GoDocument();
        GoXmlReader reader = new GoXmlReader();
        reader.AddTransformer(new TransformModuleNode());
        reader.AddTransformer(new TransformModuleNodePort());
        reader.AddTransformer(new TransformerDescription());
        reader.AddTransformer(new TransformerSize());
        reader.AddTransformer(new TransformerPosition());
        reader.AddTransformer(new TransformerShape());
        reader.RootObject = doc;
        StreamReader file = new StreamReader("library.xml");

class TransformerShape : GoXmlTransformer
public TransformerShape()
ElementName = “shape”;
TransformerType = typeof(GoObject);
BodyConsumesChildElements = true;

    public override void ConsumeAttributes(object obj)
        Debug.WriteLine("TransformerShape.ConsumeAttributes called");

The method ConsumeAttributes of my TransformerShape class gets called numerous times, even when there isn’t a element “shape” in the XML. If I change the TransformerType to something else, say a GoBalloon, the ConsumeAttributers method only gets called for each occurrence of a shape element. This is the behavior is what I expect.

To me it looks like the TransformerShape.ConsumeAttributes gets called everytime it encounters a (derived) object of GoObject.

What is going on?

If you need additional information please ask.

That’s how it works. You want to (typically) just register transformers for the highest level classes in your app.

To clarify Jake’s point: you typically register transformers for the classes that you instantiate.

But sometimes it makes sense to put common code into a transformer that goes into a base class.

You might find it a lot easier to use the new GoXmlBindingTransformer in version 3.0, since in many cases you won’t need to override any methods.

Ok thank you for the answers and clarifications. I’m trying to create a GoShape based on a attribute in my XML file. That’s why is was trying to create a baseclass GoObject. I Suppose I can work around by creating a ShapeContainer.

I’ll have look at the beta today.