How to Save GraphLinksModel

I have a XML structure like this:




I managed how to load XML into GraphLinksModel by doing:
model.NodesSource = nodes;
model.LinksSource = links;
myDiagram.Model = model;

But how to do GraphLinksModel.Save?
I need to perserve the exact same XML structure.


Presumably in your app the value of “nodes” is the concatenation of the data coming from the collection of Node elements and the collection of Comment elements, because the Model.NodesSource needs to hold data for both real Nodes and “Comment” category Nodes.

If I were you, I would use Linq to XML.

Can you give me some ideas how to do GraphLinksModel.Save?
How do I save Node, Comment and Link back to XML?
“Link” links “Node”.
I don’t think model.Save<Node, Link>() will work for me because I have parent as “Nodes” and “Links” in my XML. To get a derived class from GraphLinksModel won’t give me capability to override save method. If I override insertlink and insertnode method, how to do save the whole xml?

You don’t have to use Model.Load and .Save if you don’t want to. Just write out whatever XML you need.

You mean after I got the model from diagram, I loop through model.NodesSource and model.LinksSource to generate my own xml?

Yes. Well, you would probably want to loop over the NodesSource twice, once to put out the node elements, and then again to put out the Comment elements.
If you are using Linq to XML, you can probably do everything in a single (but complex) expression that doesn’t even use any C# looping statement.