Reputation: 38631
I am defined a simple class and serialized it:
public class Test
{
public string Name { set; get; }
}
I am serized this simple object,the code like this:
Test test = new Test();
test.Name = "a";
TextWriter writer = new StreamWriter(@"D:\a.xml");
XmlSerializer s = new XmlSerializer(typeof(Test), "");
s.Serialize(writer, test);
writer.Close();
The a.xml result file like this:
<Test xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<Name>a</Name>
</Test>
That's no problem,but now i want my xml node content like this(change the default element name(like: Test) to user define name,whatever the name is(like: job-scheduling-data)):
<job-scheduling-data xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<Name>a</Name>
</job-scheduling-data>
What can i do to make it right? I don't want my class name like "job-scheduling-data".
Upvotes: 1
Views: 239
Reputation: 14919
[XmlRoot(ElementName = "job-scheduling-data")]
public class Test
{
public string Name { set; get; }
}
you can check this msdn page.
Upvotes: 2