static void writexmlbyxmlwriter (xmlwriter writer, string symbol, double price, double change, long volume)
{< br> writer. writestartelement ("stock");
writer. writeattributestring ("symbol", symbol);
writer. writeelementstring ("price", xmlconvert. tostring (price);
writer. writeelementstring ("change", xmlconvert. tostring (Change);
writer. writeelementstring ("volume", xmlconvert. tostring (volume);
writer. writeendelement ();
}
Private void createxmlfilebutton_click (Object sender, system. eventargs E)
{
// Create a string that represents the path of the XML file to be generated. If the path points to the NTFS partition, related access permissions are required.
String filename = @ "C: \ XML \ stock. xml ";
// Create a file stream for writing XML data
System. Io. filestream myfilestream = new system. Io. filestream (filename, system. Io. filemode. Create );
// Create an xmltextwriter object using a file stream object
Xmltextwriter myxmlwriter = new xmltextwriter (myfilestream, system. Text. encoding. Unicode );
Myxmlwriter. Formatting = formatting. indented;
try
{< br> // use the writexmlbyxmlwriter method to write data to the xmltextwriter object.
writexmlbyxmlwriter (myxmlwriter, "MSFT", 74.5, 5.5, 49020000 );
// by calling the close method, the data of the xmltextwriter object is finally written to the XML file
myxmlwriter. close ();
page. response. write ("XML document generated successfully! ");
}< br> catch
{< br> page. response. Write (" An error occurred while generating the XML document! Check whether the path is correct and whether you have write permission. ");
}< BR >}