I have a simple class Student under namespace School.
namespace XmlTestApp
{
public class Student
{
private string studentId;
public string FirstName;
public string MI;
public string LastName;
public Student()
{
//Just provided for making Serialization work as obj.GetType() needs parameterless constructor.
}
public Student(String studentId)
{
this.studentId = studentId;
}
}
}
Now when i serialize this, i get this as serialized xml:
<?xml version="1.0" encoding="utf-8"?>
<Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Cad</FirstName>
<MI>Dsart</MI>
<LastName>dss</LastName>
</Student>
But what i want is this, basically i need the namespace prefixed to class name in xml, is this possible?
<?xml version="1.0" encoding="utf-8"?>
<XmlTestApp:Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>Cad</FirstName>
<MI>Dsart</MI>
<LastName>dss</LastName>
</Student>
Here's my serialization code:
Student s = new Student("2");
s.FirstName = "Cad";
s.LastName = "dss";
s.MI = "Dsart";
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(s.GetType());
TextWriter txtW=new StreamWriter(Server.MapPath("~/XMLFile1.xml"));
x.Serialize(txtW,s);