The following code is generated:
<Root>
<Node key = "" value = ""> </node>
<Node> ....
</Root>
Such an XML file. Many of the following codes are custom string constants. Hashtable is also used.
Public void save ()
{
Fileinfo Fi = new fileinfo (_ filename );
If (! Fi. exists) // to do
Fi. Create ();
Xmltextwriter XW = NULL;
Try
{
Xmldocument xml = new xmldocument ();
XW = new xmltextwriter (_ filename, encoding. utf8 );
XML. writeto (XW );
System. Collections. icollection keys = _ Ht. Keys;
XW. writestartelement ("root ");
Foreach (string key in keys)
{
XW. writestartelement ("Node ");
XW. writeattributestring (key, key );
XW. writeattributestring (value, _ HT [Key] as string );
XW. writeendelement ();
}
XW. writeendelement ();
XML. Save (XW );
}
Catch (unauthorizedaccessexception)
{
// To do
// Access deny
}
Catch (exception)
{
// To do
}
Finally
{
If (null! = XW)
{
XW. Close ();
}
}
}