this is XML
<TEST ID=1 TITLE="HELLO" TEST=false/>
this file is XmlSerializer
[Serializable]
[XxmlRoot(ElementName = "TEST"]
public class TEST
{
[XmlAttribute(AttributeName = "ID"]
public int ID {get;set;}
[XmlAttribute(AttributeName = "TITLE"]
public string TITLE {get;set;}
[XmlAttribute(AttributeName = "TEST"]
public bool TEST {get;set;}
}
Run This Project
Error Message "'TEST' member names cannot be the same as their enclosing type"
I understand it. but I CAN NOT rename this AttributeName and RootName, XML file is Never Change, Not my File. How can I Change this Serializable File ?
You can rename your member variables while keeping the actual XML tags the same. The AttributeName
you have used enables this. You can actually do this:
[Serializable]
[XmlRoot(ElementName = "TEST"]
public class TestTag
{
[XmlAttribute(AttributeName = "ID"]
public int IdAttribute { get; set; }
[XmlAttribute(AttributeName = "TITLE"]
public string TitleAttribute { get; set; }
[XmlAttribute(AttributeName = "TEST"]
public bool TestAttribute { get; set; }
}
or something similar. Your XML file will remain the same!