Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Save other information to XML file (Read 2825 times)
lyrock
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Sep 12th, 2011
Save other information to XML file
Sep 12th, 2011 at 6:02pm
Print Post  
I am a new user of MindFusion.Diagramming (for VB.NET).

I am creating a network and use SaveToXML and LoadFromXML functions to save/load my network. For each node in this network, I also need to define a probability table.

When saving the network, I want to save the probability tables too. And the same thing when loading.

I looked through the help file. It looks like I have to override the SaveToXML/LoadFromXML function? Could you post an example of this in VB.NET? Or are there other approaches?

Thanks a lot.

Best,

Yan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save other information to XML file
Reply #1 - Sep 12th, 2011 at 6:29pm
Print Post  
Hi,

If the type of your probability table is serializable, you can assign the table to the node's Tag property and it will be serialized automatically. However the data will be saved as base64-encoded string inside the <Tag> element instead of human-readable xml. If you prefer the latter, you can handle the SerializeTag and DeserializeTag events to create any XML elements you'd like.

You can also create a custom node type and override its SaveToXml and LoadFromXml methods. In the methods' implementation you can either use the .NET's Xml classes to create new elements under the one provided as argument, or use the helper methods from the XmlContext argument to create an element and set its data with a single method call. You can see this done in the "Scripting" sample project.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
lyrock
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Sep 12th, 2011
Re: Save other information to XML file
Reply #2 - Sep 13th, 2011 at 3:01pm
Print Post  
Thank you for your help. The serialization method is really handy.

I just came across another question:

How to find out all the parents/grandparents/.... (hierarchy structure) of a certain node? Any good example? Thanks again.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save other information to XML file
Reply #3 - Sep 13th, 2011 at 3:17pm
Print Post  
Try this for parent nodes:
DiagramItemCollection items = diagram.ActiveItem.Query("inlinks/origin");

and for grandparents:
DiagramItemCollection items = diagram.ActiveItem.Query("inlinks/origin/inlinks/origin");

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
lyrock
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Sep 12th, 2011
Re: Save other information to XML file
Reply #4 - Sep 13th, 2011 at 3:45pm
Print Post  
Those codes work for C#. But I am working with VB.NET. Sad

If my node is at a very low level, and I don't know how many levels of parents/grandparents it has, how do I handle this situation? Because I am not going to know exactly how many "inlinks/orgin" to be included in the command.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save other information to XML file
Reply #5 - Sep 13th, 2011 at 6:09pm
Print Post  
This will return all nodes up in the graph:

Code
Select All
Function GetPredecessors(ByVal node As DiagramNode) As List(Of DiagramNode)
	Dim predecessors As New List(Of DiagramNode)

	' run breadth-first search trough this queue
	Dim queue As New Queue(Of DiagramNode)
	queue.Enqueue(node)

	While queue.Count > 0
		Dim pred As DiagramNode = queue.Dequeue
		If Not predecessors.Contains(pred) Then
			predecessors.Add(pred)
			For Each parent As DiagramNode In pred.Query("inlinks/origin")
				queue.Enqueue(parent)
			Next
		End If
	End While

	' remove the argument node
	predecessors.RemoveAt(0)

	Return predecessors
End Function 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint