Representing XML file
-
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,
-
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,
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; } } }
}
-
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; } } }
}
thxx sir i ll use this code Regards,