зеркало из https://github.com/mono/mail-archives.git
188 строки
6.3 KiB
HTML
188 строки
6.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE> [Mono-list] Serializing a Graph ..
|
|
</TITLE>
|
|
<LINK REL="Index" HREF="index.html" >
|
|
<LINK REL="made" HREF="mailto:David%20Waite%20%3Cdwaite%40gmail.com%3E">
|
|
<META NAME="robots" CONTENT="index,nofollow">
|
|
|
|
<LINK REL="Previous" HREF="025879.html">
|
|
<LINK REL="Next" HREF="025937.html">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#ffffff">
|
|
<H1>[Mono-list] Serializing a Graph ..
|
|
</H1>
|
|
<B>David Waite
|
|
</B>
|
|
<A HREF="mailto:David%20Waite%20%3Cdwaite%40gmail.com%3E"
|
|
TITLE="[Mono-list] Serializing a Graph ..">David Waite <dwaite@gmail.com>
|
|
</A><BR>
|
|
<I>Sun, 20 Feb 2005 20:56:44 -0700</I>
|
|
<P><UL>
|
|
<LI> Previous message: <A HREF="025879.html">[Mono-list] Serializing a Graph ..
|
|
</A></li>
|
|
<LI> Next message: <A HREF="025937.html">[Mono-list] Serializing a Graph ..
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#25880">[ date ]</a>
|
|
<a href="thread.html#25880">[ thread ]</a>
|
|
<a href="subject.html#25880">[ subject ]</a>
|
|
<a href="author.html#25880">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
<HR>
|
|
<!--beginarticle-->
|
|
<PRE>the normal serialization is a bag of unique objects with references
|
|
between them; formatting with Xml implies a parent/child relationship.
|
|
The xml serializer as it exists does not make allowances to directly
|
|
create or use ID/IDREF relationships, which is what you really need
|
|
for your cyclic data structure.
|
|
|
|
-David Waite
|
|
|
|
On Mon, 21 Feb 2005 00:05:00 +0000, Phillip Neumann <<A HREF="mailto:bob@sofsis.cl">bob@sofsis.cl</A>> wrote:
|
|
><i>
|
|
</I>><i>
|
|
</I>><i> Ive just made the same with BinaryFormatetr, instead of XmlSerialize
|
|
</I>><i>
|
|
</I>><i> Why does it work? Why does XmlSerilize not work?
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> Phillip Neumann wrote:
|
|
</I>><i>
|
|
</I>><i> > Hello all...
|
|
</I>><i> >
|
|
</I>><i> > Im doing some work with Graph, so create some clases:
|
|
</I>><i> >
|
|
</I>><i> > Node
|
|
</I>><i> > Arc
|
|
</I>><i> > Graph.
|
|
</I>><i> >
|
|
</I>><i> > (A Graph is a list of Nodes)
|
|
</I>><i> >
|
|
</I>><i> > I like the idea about been able to save/load a graph to/from disk.
|
|
</I>><i> > Im trying to XmlSerialize my graph.
|
|
</I>><i> >
|
|
</I>><i> > I have define my graph so, that this cannot be made, becouse:
|
|
</I>><i> > 1.- Node = { X, Y, ListOfOutgoingArcs }
|
|
</I>><i> > 2.- Arc = { StartNode, StopNode, Weight}
|
|
</I>><i> >
|
|
</I>><i> > This definition is circular....
|
|
</I>><i> >
|
|
</I>><i> > What do u think is the best to modify, for let the graph been saved to
|
|
</I>><i> > disk?
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i> > When i run this, i get this:
|
|
</I>><i> > <mono1.0.5>
|
|
</I>><i> > System.InvalidOperationException: A cirtular reference was detected
|
|
</I>><i> > while serializing an object of type Node
|
|
</I>><i> > </mono>
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i> > thanks in advance,
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i> >------------------------------------------------------------------------
|
|
</I>><i> >
|
|
</I>><i> >using System;
|
|
</I>><i> >using System.Xml;
|
|
</I>><i> >using System.Xml.Serialization;
|
|
</I>><i> >using System.Collections;
|
|
</I>><i> >
|
|
</I>><i> >[Serializable, XmlInclude(typeof(Arc))]
|
|
</I>><i> >public class Node{
|
|
</I>><i> >
|
|
</I>><i> > public ArrayList OutGoingArcs = new ArrayList();
|
|
</I>><i> > public int X;
|
|
</I>><i> > public int Y;
|
|
</I>><i> > public Node(){}
|
|
</I>><i> > public Node(int x,int y){
|
|
</I>><i> > X=x;
|
|
</I>><i> > Y=y;
|
|
</I>><i> >
|
|
</I>><i> > }
|
|
</I>><i> >
|
|
</I>><i> >}
|
|
</I>><i> >
|
|
</I>><i> >public class Arc{
|
|
</I>><i> > public int Weight;
|
|
</I>><i> > public Node StartAt;
|
|
</I>><i> > public Node EndAt;
|
|
</I>><i> > public Arc(){}
|
|
</I>><i> > public Arc(Node n1, Node n2){
|
|
</I>><i> > StartAt=n1;
|
|
</I>><i> > EndAt = n2;
|
|
</I>><i> > n1.OutGoingArcs.Add(this);
|
|
</I>><i> > }
|
|
</I>><i> >
|
|
</I>><i> >}
|
|
</I>><i> >
|
|
</I>><i> >[Serializable, XmlInclude(typeof(Node))]
|
|
</I>><i> >public class Graf{
|
|
</I>><i> > public ArrayList Nodes;
|
|
</I>><i> >
|
|
</I>><i> > public Graf (){
|
|
</I>><i> > Nodes = new ArrayList();
|
|
</I>><i> > }
|
|
</I>><i> >
|
|
</I>><i> > public void Add(Node n){
|
|
</I>><i> > Nodes.Add(n);
|
|
</I>><i> > }
|
|
</I>><i> >}
|
|
</I>><i> >
|
|
</I>><i> >public class M{
|
|
</I>><i> >
|
|
</I>><i> > public static void Main(){
|
|
</I>><i> >
|
|
</I>><i> > Graf g = new Graf();
|
|
</I>><i> >
|
|
</I>><i> > Node n1 = new Node(1,1);
|
|
</I>><i> > Node n2 = new Node(2,2);
|
|
</I>><i> >
|
|
</I>><i> > Arc a1=new Arc(n1,n2);
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i> > g.Add(n1);
|
|
</I>><i> > g.Add(n2);
|
|
</I>><i> >
|
|
</I>><i> > XmlSerializer seria = new XmlSerializer(typeof(Graf));
|
|
</I>><i> > seria.Serialize(Console.Out,g);
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i> > }
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i> >}
|
|
</I>><i> >
|
|
</I>><i> >
|
|
</I>><i>
|
|
</I>><i> --
|
|
</I>><i>
|
|
</I>><i> _________________________
|
|
</I>><i> Phillip Neumann
|
|
</I>><i> <A HREF="mailto:phillip@sofsis.cl">phillip@sofsis.cl</A>
|
|
</I>><i> www.sofsis.cl
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>
|
|
</PRE>
|
|
<!--endarticle-->
|
|
<HR>
|
|
<P><UL>
|
|
<!--threads-->
|
|
<LI> Previous message: <A HREF="025879.html">[Mono-list] Serializing a Graph ..
|
|
</A></li>
|
|
<LI> Next message: <A HREF="025937.html">[Mono-list] Serializing a Graph ..
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#25880">[ date ]</a>
|
|
<a href="thread.html#25880">[ thread ]</a>
|
|
<a href="subject.html#25880">[ subject ]</a>
|
|
<a href="author.html#25880">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
</body></html>
|