Blog Post :
Using XmlSerializer with external serializable types
Listing 4 : Application Main() source code
static
void
Main(
string
[] args)
{
// Pretty-print (Altova terminology) the XML.
AppData.Serializer.PrettyPrint =
true
;
// TODO: Change the relative location as approriate..
string
testXmlInFilePath = @
"..\..\schema\"
;
// Read and de-serialize test.001.xml.
string
folderPath = Path.GetDirectoryName(Path.GetFullPath(testXmlInFilePath));
string
xml = ReadFile(Path.Combine(folderPath,
"test.001.xml"
));
AppData.ExtensibleDataType appData = AppData.ExtensibleDataType.FromXml(xml);
// Create and add an ExternData node.
WebsiteData.Website websiteData =
new
WebsiteData.Website();
websiteData.Url =
"http://xml-fx.com"
;
websiteData.Contact =
"Joe Bloggs"
;
websiteData.Email =
"info@xml-fx.com"
;
appData.ExternData = websiteData;
xml = appData.Xml;
// Serialize and write test.002.xml.
WriteFile(Path.Combine(folderPath,
"test.002.xml"
), xml);
// Read and de-serialize test.002.xml.
xml = ReadFile(Path.Combine(folderPath,
"test.002.xml"
));
appData = AppData.ExtensibleDataType.FromXml(xml);
// Change some ExternData info.
websiteData = appData.ExternData
as
WebsiteData.Website;
if
(websiteData !=
null
)
{
websiteData.Contact =
"John Thomas"
;
}
xml = appData.Xml;
// Serialize and write test.003.xml.
WriteFile(Path.Combine(folderPath,
"test.003.xml"
), xml);
}