Asp.net generates XML files

Source: Internet
Author: User

Method 1: use dataset directly

Sqlconnection conn = new sqlconnection (); <br/> Conn. connectionstring = "Server = 127.0.0.1; user id = sa; Password = sa; database = northwind; persist Security info = true"; <br/> Conn. open (); <br/> sqldataadapter da = new sqldataadapter ("select * from table", Conn); <br/> sqlcommandbuilder thisbulder = new sqlcommandbuilder (DA ); <br/> dataset DS = new dataset (); <br/> da. fill (DS); <br/> DS. writexml (@ "C:/temp. XML ");

Method 2: Custom generation mode

using system. XML; // Add this namespace to the header <br/> xmldocument XD = new xmldocument (); // indicates the XML document <br/> xmldeclaration xde; // indicates the XML declaration node: <? XML version = '1. 0'...?> <Br/> xde = XD. createxmldeclaration ("1.0", "GBK", null ); // The second item of the parameter is the encoding method <br/> // standalone defines whether the document can be processed without reading any other files, default Value: No <br/> XD. appendchild (xde); // <? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?> Generation ended <br/> xmlelement Xe = XD. createelement ("root"); // create a root element <br/> XD. appendchild (xe); // root element created <br/> xmlnode root = XD. selectsinglenode ("root"); // find <root> <br/> xmlelement xe1 = XD. createelement ("Tree"); // create an element under <root> <tree> <br/> xe1.setattribute ("ID", "1 "); // specify the property value <br/> xe1.innertext = "Type 1"; // specify the property text node <br/> root. appendchild (xe1); // subnode completion <tree> <br/> XD. save (server. mappath ("XML. XML ");

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.