Scenario:
You want to serialize the data from a class
Class:
public class Address {XML Output:
public string Address1;
public string Address2;
public string City;
public string State;
public string Zip;
}
<?xml version="1.0" encoding="utf-8"?>Code:
<Address>
<Address1>One Microsoft Way</Address1>
<City>Redmond</City>
<State>WA</State>
<Zip>98052</Zip>
</Address>
Address oAddress = new Address();
XmlSerializer serializer = new XmlSerializer(typeof(Address));
TextWriter writer = new StreamWriter(@"c:\addresses.xml");
serializer.Serialize(writer, oAddress);
writer.Close();
0 comments:
Post a Comment