Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. saving graph as an xml file

saving graph as an xml file

Scheduled Pinned Locked Moved C#
graphicsdata-structuresxmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mamphekgo Bahula
    wrote on last edited by
    #1

    hi i have created this method to display graph on a form and is display but the problem that i have is that i want to save this method as an xml file but i can't get it right.under this method there is code that i am trying to use to save this method as an xml file. private void DisplayTools() { Graph g = Graph("graph"); g.AddNode("Circle"); g.AddNode("Box"); g.AddNode("Ellipse"); g.AddNode("Diamond"); Edge e1 = (Edge)g.AddEdge("Circle", "Box"); Edge e2 = (Edge)g.AddEdge("Box", "Ellipse"); Edge e3 = (Edge)g.AddEdge("Ellipse", "Diamond"); Edge e4 = (Edge)g.AddEdge("Diamond", "Circle"); Node n1 = (Node)g.FindNode("Circle"); n1.Attr.Color = Microsoft.Glee.Drawing.Color.Black; n1.Attr.Shape = Shape.Circle; Node n2 = (Node)g.FindNode("Box"); n2.Attr.Color = Microsoft.Glee.Drawing.Color.Black; n2.Attr.Shape = Shape.Box; Node n3 = (Node)g.FindNode("Diamond"); n3.Attr.Color = Microsoft.Glee.Drawing.Color.Black; n3.Attr.Shape = Shape.Diamond; gViewer1.Graph = g; here is code that i am trying to use to save as an xml file FileStream fs = new FileStream("methods.xml", FileMode.Create); XmlTextWriter w = new XmlTextWriter(fs,Encoding.UTF8); w.WriteStartDocument(); w.WriteStartElement("methods"); DisplayTools(); w.WriteEndElement(); w.WriteEndDocument(); w.Flush(); fs.Close();

    Mamphekgo

    R 1 Reply Last reply
    0
    • M Mamphekgo Bahula

      hi i have created this method to display graph on a form and is display but the problem that i have is that i want to save this method as an xml file but i can't get it right.under this method there is code that i am trying to use to save this method as an xml file. private void DisplayTools() { Graph g = Graph("graph"); g.AddNode("Circle"); g.AddNode("Box"); g.AddNode("Ellipse"); g.AddNode("Diamond"); Edge e1 = (Edge)g.AddEdge("Circle", "Box"); Edge e2 = (Edge)g.AddEdge("Box", "Ellipse"); Edge e3 = (Edge)g.AddEdge("Ellipse", "Diamond"); Edge e4 = (Edge)g.AddEdge("Diamond", "Circle"); Node n1 = (Node)g.FindNode("Circle"); n1.Attr.Color = Microsoft.Glee.Drawing.Color.Black; n1.Attr.Shape = Shape.Circle; Node n2 = (Node)g.FindNode("Box"); n2.Attr.Color = Microsoft.Glee.Drawing.Color.Black; n2.Attr.Shape = Shape.Box; Node n3 = (Node)g.FindNode("Diamond"); n3.Attr.Color = Microsoft.Glee.Drawing.Color.Black; n3.Attr.Shape = Shape.Diamond; gViewer1.Graph = g; here is code that i am trying to use to save as an xml file FileStream fs = new FileStream("methods.xml", FileMode.Create); XmlTextWriter w = new XmlTextWriter(fs,Encoding.UTF8); w.WriteStartDocument(); w.WriteStartElement("methods"); DisplayTools(); w.WriteEndElement(); w.WriteEndDocument(); w.Flush(); fs.Close();

      Mamphekgo

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      You need to decorate Graph and its contained classes with XML serialization attributes. See this[^] tutorial. /ravi

      This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups