I did some research may be following answer helps
For Attributes to have namespace prefix you have to specify a different namespace tag other than what you have specified http://foo
. Following code hopefully will solve your issue. In the code i have remove the namespace for elements and added only for the attribute.
public class IncidentEvent
{
public string EventDate { get; set; }
public string EventTime { get; set; }
[XmlAttribute("EventTypeText", Namespace = "http://foo")]
public string EventTypeText { get; set; }
}
class Program
{
static void Main(string[] args)
{
IncidentEvent xmlObj = new IncidentEvent()
{
EventDate = "2012.12.01",
EventTime = "1:00:00",
EventTypeText = "Beginining"
};
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("ett", "http://foo");
XmlSerializer serializer = new XmlSerializer(typeof(IncidentEvent));
serializer.Serialize(Console.OpenStandardOutput(), xmlObj, ns);
Console.WriteLine();
}
}
http://www.w3.org/TR/2009/REC-xml-names-20091208/#defaulting