UserObject and XML Example


Do you have an example of how the UserObject of a GoBasicNode can be bound to an XML attribute using the GoXmlBindingTransformer?

I have tried the following:

//Sample node in the XML

<node id=“733A02B8-CED7-4FC9-8DE5-6324A5E62572” label=“002 ASSEMBLY” parent=“7DF3DB0F-21A8-4C80-A275-5451136A18B5” type=“1” userobject=“733A02B8-CED7-4FC9-8DE5-6324A5E62572” />

//default node and binding code

GoBasicNode n = new GoBasicNode();
n.Shape = new GoRectangle();
n.LabelSpot = GoObject.Middle;
n.Text = “”;
n.Label.FontSize = 6;
n.Shape.BrushStyle = GoBrushStyle.Solid;
n.AutoResizes = true;

GoXmlBindingTransformer tr = new GoXmlBindingTransformer(“node”, n);

tr.IdAttributeUsedForSharedObjects = true;
tr.TreeLinkPrototype = l;
tr.TreeLinksToChildren = true;
tr.AddBinding(“label”, “Label.Text”);
tr.AddBinding(“parent”, “TreeParentNode”);
tr.AddBinding(“type”, “UserFlags”);
tr.AddBinding(“userobject”, “ToolTipText”);
tr.AddBinding(“userobject”, “UserObject”);
tr.AddBinding(“userobject”, “PartID”);

I attempt to retrieve the values at runtime through a click event:

private void govBOM_ObjectDoubleClicked(object sender, Northwoods.Go.GoObjectEventArgs e)
GoObject oBOM = e.GoObject;

        GoBasicNode n = oBOM.TopLevelObject as GoBasicNode;
        if (n != null)

Now, when I access the node at runtime, I get the GUID from n.ToolTipText, a “-1” from n.PartID and a GoBasicNode object equal n as n.UserObject.

Am I missing something elementary in setting up the document, the template node or the transformation?

UserObject is type Object, and the XML code doesn’t have any idea about how to convert it to/from text.

What are you storing in UserObject?


I understand that the UserObject is a type Object, but I had seen other users on the forum with an “addBinding” for UserObject and thought I was just missing something. I’m curious how their XML is structured to get the binding to stick.

I finally figured out that the UserObject isn’t a viable source for storing key data when using the XML transformation, so I just created my own node class with a string property that I can bind to.

The value I was attempting to store was a Guid/String.

Again, if I’m missing something elementary, I’d be interested in knowing how to bind to the UserObject from XML, but for now, I’ve come up with a pretty solid solution in the custom node class.


Well, just guessing here, I think the code may do a .ToString() on the object. and depending on the object, that may or may be useful.