Save\Load XML problem

<span id=“result_” =""="" lang=“en”><span =“hps”="">I learned <span =“hps”="">how to save <span =“hps”="">chart data <span =“hps”="">to a file. <span =“hps”="">I decided to try <span =“hps”="">a <span =“hps”="">simple example: keep <span =“hps”="">only one node<span =""="">.

    public void RegisterTransformers(GoXmlReaderWriterBase rw)
    {
        var doc = new GoDocument();
        var bt = new GoXmlBindingTransformer("graph", doc);
        rw.AddTransformer(bt);
        var bn = new GoSimpleNode();
       <font color="#CC0000"> bn.Initialize(null,null,"hello");</font>
        var bt1 = new GoXmlBindingTransformer("node", bn);
        // generates attributes for all named ports, to define their id's
        // without generating separate elements for them
        bt1.HandlesNamedPorts = true;
        // map the "label" attribute to the GoBasicNode.Text property
        bt1.AddBinding("label", "Text");
        // the "color" attribute is the GoBasicNode.Shape.BrushColor property
        bt1.AddBinding("color", "Shape.BrushColor");
        bt1.AddBinding("loc", "Location");
        bt1.AddBinding("figur", "Figure");
        rw.AddTransformer(bt1);
         }

My method for saving:
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var xw = new GoXmlWriter();
RegisterTransformers(xw);
xw.Objects = goView1.Document;
using (var file = new StreamWriter(Application.UserAppDataPath+@"\test.xml"))
{
xw.Generate(file);
}
}

Method to read:
private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var xr = new GoXmlReader();
RegisterTransformers(xr);
using (var file = new StreamReader(Application.UserAppDataPath + @"\test.xml"))
{
goView1.Document = (GoDocument)xr.Consume(file);
}
}

And i have no result after reading method. Plz help.

P.S. I fixed problem. <span id=“result_” =“short_text” lang=“en”><span =“hps”>I outlined <span =“hps”>the solution <span =“hps”>red.

next problem: how to save\read link.
now my RegisterTransformetrs look like:
public void RegisterTransformers(GoXmlReaderWriterBase rw)
{
var doc = new GoDocument();
var bt = new GoXmlBindingTransformer(“graph”, doc);
rw.AddTransformer(bt);
var bn = new GoSimpleNode();
bn.Initialize(null,null,“hello”);
// bn.OutPort
// bn.LabelSpot = GoObject.Middle;
bn.Text = “”;
var bt1 = new GoXmlBindingTransformer(“node”, bn);
// generates attributes for all named ports, to define their id’s
// without generating separate elements for them
bt1.HandlesNamedPorts = false;
// map the “label” attribute to the GoBasicNode.Text property
bt1.AddBinding(“label”, “Text”);
// the “color” attribute is the GoBasicNode.Shape.BrushColor property
bt1.AddBinding(“color”, “Shape.BrushColor”);
bt1.AddBinding(“loc”, “Location”);
bt1.AddBinding(“figur”, “Figure”);
bt1.AddBinding(“IPort”, “InPort”);
bt1.AddBinding(“OPort”, “OutPort”);
bt1.AddBinding(“IconSize”, “Icon.Size”);
bt1.AddBinding(“IconResizable”, “Icon.Resizable”);
bt1.AddBinding(“InPortStylegur”, “InPort.Style”);
bt1.AddBinding(“InPortPen”, “InPort.Pen”);
bt1.AddBinding(“InPortBrushColor”, “InPort.BrushColor”);
bt1.AddBinding(“OutPortStyle”, “OutPort.Style”);
bt1.AddBinding(“OutPortPen”, “OutPort.Pen”);
bt1.AddBinding(“OutPortBrushColor”, “OutPort.BrushColor”);

        rw.AddTransformer(bt1);

            var ll = new GoLink {ToArrow = true, AdjustingStyle = GoLinkAdjustingStyle.Calculate,};
           var bt2 = new GoXmlBindingTransformer("link", ll);
           bt2.AddBinding("from", "FromPort");
           bt2.AddBinding("to", "ToPort");
           rw.AddTransformer(bt2);
       
    }

And now nodes are correct, but there are no links in doc.

Are you using GoLink or GoLabeledLink in your app?

private void GoView1LinkCreated(object sender, GoSelectionEventArgs e)
{

/// there was GoLink
}

i am using GoLink.

Are you creating the links in code (and adding them to GoDocument), or just with user clicking on a port in a node?

clicking on a port in a node.
Is it matter?

Clicking on a port uses GoView.NewLinkClass or NewLinkPrototype to know what link object to create… check your app for setting of either of those properties.

here my constructor:
public Admin()
{
InitializeComponent();
treeList1.Nodes.TreeList.SelectImageList = imageCollection2;
treeList2.Nodes.TreeList.SelectImageList = imageCollection2;
treeList3.Nodes.TreeList.SelectImageList = imageCollection2;
//goView1.NewGoLabeledLink = true;
goView1.NewGoLink.Orthogonal = false;
goView1.NewGoLink.Style = GoStrokeStyle.Bezier;
goView1.NewGoLink.Reshapable = false;
goView1.NewGoLink.HighlightWhenSelected = true;
goView1.NewGoLink.HighlightPenColor = Color.Magenta;
goView1.NewGoLink.HighlightPenWidth = 5;
goView1.NewGoLink.PenColor = Color.Black;
goView1.NewGoLink.PenWidth = 2;
goView1.NewGoLink.BrushColor = Color.Black;
goView1.NewGoLink.ToArrow = true;
// ribbonControl1.Images = imageCollection1;
}
link prototype is:
new GoLink() { ToArrow = true,PenWidth = 2, Orthogonal = true, Style = GoStrokeStyle.Bezier, PenColor = Color.Black, BrushColor = Color.Black, Reshapable = false } );
bt2.AddBinding(“from”, “FromPort”);
bt2.AddBinding(“to”, “ToPort”);
rw.AddTransformer(bt2);

Should i do like this?:
GoXmlBindingTransformer bt2 = new GoXmlBindingTransformer(“link”,GoView1.NewGoLink) ???

xml file is:


2 nodes and 1 link.
In application i created 2 nodes and 1 link in user interface and then i saved xml file.
then i restart my appl and click on read button, which call method:
var xr = new GoXmlReader();
RegisterTransformers(xr);
using (var file = new StreamReader(Application.UserAppDataPath + @"\test.xml"))
{
goView1.Document = (GoDocument)xr.Consume(file);
}
as the result was loaded 2 nodes whithout any link.

Goview.NewGoLink set on Northwoods.Go.GoLink
Goview.NewLinkPrototype set on Northwoods.Go.GoLink

ok… you want:

bt1.HandlesNamedPorts = true;


and add:


bt1.IdAttributeUsedForSharedObjects = true;


and get rid of:


bt1.AddBinding(“IPort”, “InPort”);
bt1.AddBinding(“OPort”, “OutPort”);

I haven't tried to reproduce your issue, but I think this will help.

Thank you very much!!!

bt1.IdAttributeUsedForSharedObjects = true; it helps me. All ok now!!!