XML: duplicate xmlElements when using subclasses

Dear experts,

I have a subclass ContainerWithParametersNode of class SimpleContainerNode, which is a subclass of GoSubGraph.

If i use the following code, in the created xmlDoc are duplicate entries (XmlElements) for the ContainerWithParametersNode objects.
If i remove the blue code, there are no longer duplicate entries.

What is (could be) the reason?

Kind regards,
Juergen Jaeger

 public XmlDocument ModelToXmlDocument(IMoBiSpaceDiagramModel diagramModel)
  {
     GoXmlWriter writer = new GoXmlWriter();
     RegisterTransformers(writer);
     writer.Objects = (SpaceDiagramModel)diagramModel;
     var xmlDoc =  writer.Generate();
     return xmlDoc;
  }

  private void RegisterTransformers(GoXmlReaderWriterBase rw)
  {
     GoXmlBindingTransformer bt;

     SpaceDiagramModel spaceDiagramModel = new SpaceDiagramModel();
     bt = new GoXmlBindingTransformer(ElementName, spaceDiagramModel);
     bt.AddBinding("ParametersVisible");
     rw.AddTransformer(bt);

     bt = new GoXmlBindingTransformer(new SimpleNeighborhoodNode());
     addNeighborhoodNodeBindings(bt);
     rw.AddTransformer(bt);

    <font color="#0000ff"> bt = new GoXmlBindingTransformer(new SimpleContainerNode());
     addContainerBaseNodeBindings(bt);
     rw.AddTransformer(bt);
bt = new GoXmlBindingTransformer(new ContainerWithParametersNode()); addContainerBaseNodeBindings(bt); rw.AddTransformer(bt); }
  private void addContainerBaseNodeBindings(GoXmlBindingTransformer bt)
  {
     bt.HandlesChildren = true;
     bt.HandlesChildAttributes = true;
     bt.HandlesSubGraphCollapsedChildren = true;
     addBaseNodeBindings(bt);
     bt.AddBinding("IsLogical");
     bt.AddBinding("IsExpanded");
  }

=>

I think you need to change the transformer for “ContainerWithParametersModel” not to call “addBaseNodeBindings”.

Of course I can’t be sure, because I don’t know what that method does.

I changed the code to:

  private void addContainerBaseNodeBindings(GoXmlBindingTransformer bt)
  {
     bt.HandlesChildren = true;
     bt.HandlesChildAttributes = true;
     bt.HandlesSubGraphCollapsedChildren = true;
     bt.AddBinding("Id");
     bt.AddBinding("Name");
     bt.AddBinding("IsExpanded");
  }

and I used also explicit element names

     bt = new GoXmlBindingTransformer("simpleContainerNode", new SimpleContainerNode());
     addContainerBaseNodeBindings(bt);
     rw.AddTransformer(bt);

     bt = new GoXmlBindingTransformer("containerWithParametersNode", new ContainerWithParametersNode());
     addContainerBaseNodeBindings(bt);
     rw.AddTransformer(bt);

Unfortunately the result remains the same:

... ...

Oh, I see that you mean that there are duplicates of the child nodes.

Perhaps it would help if you only set the “Handles…Child…” properties on the Transformer for the base class. I suspect that setting “HandlesChildren” on both the base class Transformer and the sub-class Transformer will cause them to both generate/consume child elements.

And as I suggested before, you probably don’t want to duplicate the generation of attributes either. If the base class is writing/reading properties/attributes for itself, the derived class doesn’t have to – it just needs to add bindings for its own additional properties/attributes. I think you’re not actually seeing duplicate attributes because XML doesn’t allow duplicates. However, there’s no reason to waste time trying to generate duplicate attributes.

After some redesign of our serialization of diagram information I have another problem.
I have the following class inheritance:
GoSubGraph -> SimpleContainerNode -> MultiPortContainerNode
SimpleContainerNode and MultiPortContainerNode have the same information for serialization (including the GoSubGraph.SavedBounds).

When I use GoXmlBindingTransformer in the following way

     var btc = new GoXmlBindingTransformer(new SimpleContainerNode());
     AddContainerBaseNodeBindings(btc);
     rw.AddTransformer(btc);

     bt = new GoXmlBindingTransformer(new MultiPortContainerNode());
     // bt.HandlesChildAttributes = true;
     // bt.HandlesSubGraphCollapsedChildren = true;
     rw.AddTransformer(bt);

for MultiPortContainerNodes the SavedBounds are not stored.
When uncommenting the two lines, they are stored.

So those lines seem to be necessary.
The line b.HandlesChildren seem to be a mistake, because then nodes are duplicated.
bt.AddBinding(…) seem to be possible, but not necessary from your last reply.

Does there exist anywhere a description how to do serialization with GoXmlBindingTransformer for class hierarchies (derived classes) of custom nodes and links?

I would really appreciate to get such a description, because I do not understand the logic from the users guide only.

<span =“apple-style-span”=“” style=“: rgb248, 248, 252; “>HandlesChildAttributes<span =“apple-style-span”=”” style=“: rgb248, 248, 252; “> and <span =“apple-style-span”=”” style=“: rgb248, 248, 252; “>HandlesSubGraphCollapsedChildren = true will generate SavedBounds and SavedPath info for children if subgraph is collapsed.
<span =“apple-style-span”=”” style=“: rgb248, 248, 252; “>

<span =“apple-style-span”=”” style=“: rgb248, 248, 252; “>In addition to the User Guide XML section, there is pretty detailed directions in the API reference (accessible via help in Visual Studio). In particular, the method GenerateChildAttributes help says it won’t do anything unless <span =“apple-style-span”=”” style=“: rgb248, 248, 252; “>HandlesChildAttributes<span =“apple-style-span”=”” style=“: rgb248, 248, 252; “> and <span =“apple-style-span”=”” style=“: rgb248, 248, 252; “>HandlesSubGraphCollapsedChildren<span =“apple-style-span”=”” style=“: rgb248, 248, 252; “> are both true.
<span =“apple-style-span”=”” style=“: rgb248, 248, 252; “>

<span =“apple-style-span”=”” style=": rgb248, 248, 252; ">The API references are also available online at http://www.nwoods.com/components/dotnet/documentation.htm

Thanks for your remarks, which I already found in Studio Help, when I browsed it.

I have not found any advice how to use GoXmlBindingTransformer classes when applying to a class hierarchy / subclasses (e.g. GoSubGraph -> SimpleContainerNode -> MultiPortContainerNode).

And the situation seems to be difficult then. From our discussion I found different hints for different properties/methods of GoXmlBindingTransformer:
a) HandlesChildren should NOT be used for transformer of subclasses,
b) HandlesChildAttributes, HandlesSubGraphCollapsedChildren MUST probably be used for transformer of subclasses,
c) AddBinding(…) can be used or not for transformer of subclasses.

How can I get information, which methods/properties can/must/must not be used for for transformer of subclasses ?

<span =“Apple-style-span” style=": rgb248, 248, 252; “>a) HandlesChildren should NOT be used for transformer of subclasses,
<span =“Apple-style-span” style=”: rgb248, 248, 252; “>

<span =“Apple-style-span” style=”: rgb248, 248, 252; “>I don’t see where you are seeing that.
<span =“Apple-style-span” style=”: rgb248, 248, 252; “>

<span =“Apple-style-span” style=”: rgb248, 248, 252; “>But, let me try to restate your problem to be sure I’m understanding you. I’m guessing a bit here as I don’t have a sample of the current XML output with the duplication nodes.
<span =“Apple-style-span” style=”: rgb248, 248, 252; “>

<span =“Apple-style-span” style=”: rgb248, 248, 252; “>you get duplicate nodes, but when you try to fix that, you lose SavedBounds, right?
<span =“Apple-style-span” style=”: rgb248, 248, 252; “>

<span =“Apple-style-span” style=”: rgb248, 248, 252; ">you get duplicate nodes under MultiPortContainerNode but not SimpleContainerNode… is that right?

Please look at walters entry from 07-April-2011 at 2:04pm on this post: In line 2 to 4 you should see, what I am seeing ;-)
And he was right: removing the HandleChildren from superclass fixed that problem.

Your are right: I had the problem with duplicate nodes only for MultiPortContainerNode but not for SimpleContainerNode.
When just using:
bt = new GoXmlBindingTransformer(new MultiPortContainerNode());
rw.AddTransformer(bt);
I lose SavedBounds.

It seems that I fixed my problem when not using HandleChildren, but not using HandlesChildAttributes, HandlesSubGraphCollapsedChildren for the GoXmlBindingTransformer of my subclass.
And it seems to be invariant (not necessary) to implement the AddBinding(…) for the derived properties of my subclass.

But as long as I don’t understand how GoXmlBindingTransformers work for super and subclasses,
I am not sure, whether I have a stable solution - and my and my clients quality requirements demand a stable solution.

Therefore please give me a description how GoXmlBindingTransformers should be used for super and subclasses!

There’s not rocket science in my classes. You should be able tor reproduce the whole thing with
GoSubGraph > SimpleContainerNode > MultiPortContainerNode where SimpleContainerNode has some additional property.

Best regards

OK… I got the whole picture now. Yeah… let me write some code.

If I do

<span =“Apple-style-span” style=": rgb248, 248, 252; "> bt = new GoXmlBindingTransformer(new MultiPortContainerNode());
<span =“Apple-style-span” style="text-align: left; : rgb248, 248, 252; "> bt.HandlesChildAttributes = true;
<span =“Apple-style-span” style="text-align: left; : rgb248, 248, 252; "> bt.HandlesSubGraphCollapsedChildren = true;
<span =“Apple-style-span” style="text-align: left; : rgb248, 248, 252; "> rw.AddTransformer(bt);
<span =“Apple-style-span” style="text-align: left; : rgb248, 248, 252; ">

<span =“Apple-style-span” style="text-align: left; : rgb248, 248, 252; ">I get one set of nodes (since the parent class container transformer does the child nodes) and I get the GoSubGraph.SavedBounds.

Yes, that the same experience I have made. (Sorry: in my last post was the second “not” a mistake, it should be “It seems that I fixed my problem when not using HandleChildren,
but !!! using HandlesChildAttributes, HandlesSubGraphCollapsedChildren
for the GoXmlBindingTransformer of my subclass.” ; see also my post from 4th of January.)

So, can I take your experience as an official recommendation then?

And is there a chance that e.g. to the GoDiagram FAQ is added a remark, which Properties should be used for a GoXmlBindingTransformer of a subclass and which not?

Yes, you can take that as the official recommendation for the case of having two levels of subclass under GoSubGraph.

The FAQ is an old .chm file. I’m not even sure we have the tools to build a new one anymore. I think at this point, this forum is a better resource for the unique situations people fall into.