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. Representing XML file

Representing XML file

Scheduled Pinned Locked Moved C#
questioncsharpdata-structuresxmlhelp
3 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.
  • R Offline
    R Offline
    Rizwan Rathore
    wrote on last edited by
    #1

    Hi All, I want to represent data stored in xml file in the form of a tree in a web page using C#.....how can i achieve this??? Looking forward for help Regards,

    L 1 Reply Last reply
    0
    • R Rizwan Rathore

      Hi All, I want to represent data stored in xml file in the form of a tree in a web page using C#.....how can i achieve this??? Looking forward for help Regards,

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See this example :

      using System;
      using System.IO;
      using System.Xml.Serialization;

      namespace ConsoleApplication10
      {
      class Class1
      {
      [STAThread]
      static void Main(string[] args)
      {
      SerializeToXML();
      DeserializeFromXML();
      }

      	static void SerializeToXML()
      	{
      		XmlSerializer xs = new XmlSerializer(typeof(MyDataClass));
      
      		MyDataClass mdc = new MyDataClass();
      		mdc.A = 10;
      		mdc.S = "Hello World";
      		mdc.D = new double\[3\];
      		mdc.D\[0\] = 0.456;
      		mdc.D\[1\] = 1.234;
      		mdc.D\[2\] = 4.234;
      
      		Stream writer = new FileStream("test.xml", FileMode.Create);
      		xs.Serialize(writer, mdc);
      		writer.Close();
      	}
      
      	static void DeserializeFromXML()
      	{
      		XmlSerializer xs = new XmlSerializer(typeof(MyDataClass));
      		Stream reader= new FileStream("test.xml",FileMode.Open);
      		MyDataClass mdc = (MyDataClass) xs.Deserialize(reader);
      
      		Console.WriteLine(mdc.A);
      		Console.WriteLine(mdc.S);
      		for(int i = 0; i < mdc.D.Length; i++)
      		{
      			Console.WriteLine(mdc.D\[i\]);
      		}
      	}
      }
      
      public class MyDataClass
      {
      	private int a = 0;
      	private string s = "";
      	private double\[\] d = null;
      
      	public int A
      	{
      		get { return this.a; }
      		set { this.a = value; }
      	}
      
      	public string S
      	{
      		get { return this.s; }
      		set { this.s = value; }
      	}
      
      	public double\[\] D
      	{
      		get { return this.d; }
      		set { this.d = value; }
      	}
      }
      

      }

      R 1 Reply Last reply
      0
      • L Lost User

        See this example :

        using System;
        using System.IO;
        using System.Xml.Serialization;

        namespace ConsoleApplication10
        {
        class Class1
        {
        [STAThread]
        static void Main(string[] args)
        {
        SerializeToXML();
        DeserializeFromXML();
        }

        	static void SerializeToXML()
        	{
        		XmlSerializer xs = new XmlSerializer(typeof(MyDataClass));
        
        		MyDataClass mdc = new MyDataClass();
        		mdc.A = 10;
        		mdc.S = "Hello World";
        		mdc.D = new double\[3\];
        		mdc.D\[0\] = 0.456;
        		mdc.D\[1\] = 1.234;
        		mdc.D\[2\] = 4.234;
        
        		Stream writer = new FileStream("test.xml", FileMode.Create);
        		xs.Serialize(writer, mdc);
        		writer.Close();
        	}
        
        	static void DeserializeFromXML()
        	{
        		XmlSerializer xs = new XmlSerializer(typeof(MyDataClass));
        		Stream reader= new FileStream("test.xml",FileMode.Open);
        		MyDataClass mdc = (MyDataClass) xs.Deserialize(reader);
        
        		Console.WriteLine(mdc.A);
        		Console.WriteLine(mdc.S);
        		for(int i = 0; i < mdc.D.Length; i++)
        		{
        			Console.WriteLine(mdc.D\[i\]);
        		}
        	}
        }
        
        public class MyDataClass
        {
        	private int a = 0;
        	private string s = "";
        	private double\[\] d = null;
        
        	public int A
        	{
        		get { return this.a; }
        		set { this.a = value; }
        	}
        
        	public string S
        	{
        		get { return this.s; }
        		set { this.s = value; }
        	}
        
        	public double\[\] D
        	{
        		get { return this.d; }
        		set { this.d = value; }
        	}
        }
        

        }

        R Offline
        R Offline
        Rizwan Rathore
        wrote on last edited by
        #3

        thxx sir i ll use this code Regards,

        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