Example #1
0
		public void WriteXmlAdjacencyGraph()
		{
			XmlTextWriter writer = new XmlTextWriter(Console.Out);
			writer.Formatting = Formatting.Indented;

			XmlGraphSerializer ser = new XmlGraphSerializer(Graph);
			ser.WriteXml(writer);
		}
        public void WriteReadXmlAdjacencyGraph()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(sw);
            writer.Formatting = Formatting.Indented;

            XmlGraphSerializer ser = new XmlGraphSerializer(Graph);
            ser.WriteXml(writer);

            StringReader sr = new StringReader(sw.ToString());
            XmlTextReader reader = new XmlTextReader(sr);
            AdjacencyGraph g = (AdjacencyGraph)ser.ReadXml(reader);

            ser = new XmlGraphSerializer(g);
            StringWriter swResult = new StringWriter();
            writer = new XmlTextWriter(swResult);
            writer.Formatting = Formatting.Indented;
            ser.WriteXml(writer);

            Console.WriteLine("------------ original xml ---------------");
            Console.WriteLine(sw.ToString());

            Console.WriteLine("------------ output xml ---------------");
            Console.WriteLine(swResult.ToString());

            XmlAssert.XmlEquals(sw.ToString(), swResult.ToString());
        }
 /// <summary>
 /// Output graph to xml
 /// </summary>
 /// <param name="g"></param>
 public void WriteToXml(ISerializableVertexAndEdgeListGraph g)
 {
     // output to xml
     XmlTextWriter writer = new XmlTextWriter(Console.Out);
     writer.Formatting = Formatting.Indented;
     XmlGraphSerializer ser = new XmlGraphSerializer(g);
     ser.Serialize(writer);
 }