I have a following class definition
[XmlRoot(ElementName = \"person\",Namespace = \"MyNamespace\")]
public class Perso
Do you need to use XmlSerializer
? If not, try following code:
Person.cs
Add new method:
public void Serialize(XmlWriter writer)
{
writer.WriteStartDocument();
writer.WriteStartElement("My", "Person", "MyNamespace");
writer.WriteElementString("My", "FirstName", "MyNamespace", FirstName);
writer.WriteElementString("My", "LastName", "MyNamespace", LastName);
writer.WriteEndElement();
writer.WriteEndDocument();
}
Usage
var person = new Person { FirstName = "John", LastName = "Doe" };
person.Serialize(new XmlTextWriter(Console.Out));