Problem in Deserialization

Hi everybody…

I’m saving my Graphnode images in to xml(Serialization).And while deserialization i’m not able to draw the graphlinks…And in my appln ,I’m inherited the GoGeneralNode in GraphNode.cs .So is there is anyway to do this?..plz help me…

Thankz in Advance…
Chelvan P

Yes, as the many sample applications show, you can do that.
You don’t say what the problem is–was there an exception? Did you try stepping through your code to make sure everything is happening the way you want it?

Hi Walter…,
I saved my graphdoc objects in a XML file using the method GraphDoc.Store()…so it generate a xml file perfectly. My pbm is…while reading the xml file using GraphDoc.Load() i got nullpointer excep…i.e(Object not set to reference…exception…) in the line
//in GraphDoc.Load() method…
GoPort p = doc.FindPart(id) as GoPort; //here i got excep…
if (p != null)
l.FromPort = p;

bcoz i’m inherit the GoGeneralNode in GraphNode and i’m not able set the n.InPort.PartID …
//in GraphDoc.Store()…
GraphNode n = obj as GraphNode;
if (n.InPort != null)
// writer.WriteAttributeString(“pidin”, XmlConvert.ToString(n.InPort.PartID));
// if (n.OutPort != null)
// writer.WriteAttributeString(“pidout”, XmlConvert.ToString(n.OutPort.PartID));

i.e this property is not available for GoGeneralNode and i’m not able to findthe PartId from the doc…
//in GraphDoc.Load() method…
i.e…GoPort p = doc.FindPart(id) as GoPort;

Can u able to understood wat my pbm is…?plz help me…
Thankz in advance…
Chelvan P

You need to figure out what information you need to write. In other words, you need to make sure your schema has the data you need to be able to reconstruct what you want.
Since a GoGeneralNode can have many ports, you’ll need to write out information for each one. During load, you’ll need to make sure each node has the right ports with the given IDs, so that when creating each link you will be able to resolve the correct ports.

Hi Walter,
I’m setting the port id’s while storing.But i don’t know why the pbm occured for me…
And my generated xml file is like this…











but while loading this line doesn’t return any port…plz help me…
GoPort p = doc.FindPart(id) as GoPort;
Regards,
Chelvan P

But you aren’t–I don’t see where a port with ID of either 56 or 66 has been defined in that XML.
And certainly if such port identifications aren’t generated in the XML, you couldn’t expect the loader/reader to be able to figure out which port is which on each node.

Hi walter…
Can u explain little bit more ???..and show me a sample xml …?
bcoz i didn’t get u and “nid” is automatically generated and i don’t know how to match the GraphLlink portid with the Shape portid…

thankz in advance,
chelvan P

You’ll need to modify the document Store and Load methods to customize the XML that is generated and that is loaded. ProtoApp and OrgCharter both support multiple ports on a node, although since their nodes are different, they do so in different ways.

Hi walter…
Can u plz provide a solution for my problem?

while GraphDoc.store…(i.e generating xml)
How to set port for a node???
and wat i did is…consider my nodes consist of one port each (like start and stop node…)
int left=n.LeftPortsCount;
int right=n.RightPortsCount;

if (left>0)
{
GoGeneralNodePort port=n.GetLeftPort(n.PartId);
n.AddLeftPort(port);
writer.WriteAttributeString(“pidin”, XmlConvert.ToString(n.GetLeftPort(temp).PartID));

}
else //if a node doesn’t consist inport i store a zero …
{
writer.WriteAttributeString(“pidin”, XmlConvert.ToString(0));
}

similarly for “pidout” also…am i right???

Regards,
Chelvan P

I think you are confusing several different processing stages.
First, I assume you are completely familiar with using System.Xml.
Second, the construction of a node and its ports in memory should have nothing to do with the generation of XML that represents it.
You normally construct a GoGeneralNode by doing something like:
GoGeneralNode n = new GoGeneralNode();
n.Initialize(null, “someImage.type”, “top label string”, “bottom label string”, 3, 1);
n.Location = …;
myDocument.Add(n);

That call to Initialize constructs three input ports and 1 output port, but you could pass zero and zero and do the construction of the ports individually:
GoGeneralNodePort p = n.MakePort(true); // an input port
p.Name = …; // and maybe set other properties too…
n.AddLeftPort§; // assume input ports are on left side
… then do the same for any other input ports …
p = n.MakePort(false); // an output port
p.Name = …;
n.AddRightPort§; // assume output ports are on the right side

Third, and quite independent of the construction of a node, is writing XML representing the node, its ports, and any links. You need to design the XML schema that you want to use, and then generate elements and attributes corresponding to the nodes/ports/links that you want to save. (I’m assuming you have the flexibility to design the XML format, and that you don’t have to generate a particular format that someone else has specified.)
If you look at the FlowCharter sample, you can see that in GraphDoc.Store it is storing the port IDs as attribute values in the element representing a node. It can do so because there are a fixed number of ports on a GraphNode in FlowCharter (at most 4). You need to decide if you can do the same, and if you want to. Another common alternative is to have separate nested elements, one per port. This allows for greater flexibility regarding the number of ports. Only you will know this for your particular application.
As a general rule, storing a document (whether XML or not) should not modify the contents of the document. So calling GoGeneralNode.AddLeftPort would be a no-no.

Fourth, the reading/loading of the XML does need to construct objects in memory, given the contents of the XML stream or DOM. As a general rule, loading a document should build a whole document and not use or refer to parts of any other document. Here is where you’ll want to construct a new node and call GoGeneralNode.MakePort, depending on the elements and attributes you read from the XML.
I think the sample applications also provide good examples of this.