Xmltextwriter, xmlwriter

Source: Internet
Author: User

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 >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.