Use XmlTextWriter to generate an XML file

Source: Internet
Author: User
Project compatibility requires the generation of a series of xml files. This section summarizes the basic methods for generating XML files. project compatibility requires the generation of a series of xml files, and summarizes the basic methods for generating XML files.

XmlTextWriter w = new XmlTextWriter ("C: \ XML file name. xml", Encoding. Unicode); // Encoding. Unicode indicates the Encoding format of the generated XML file, which is combined with the output:
 W. Formatting = Formatting. Indented; // This attribute indicates that the content in the xml file is Indented by level. // Start generating the file content below w. writeStartDocument (); // start to write xml. at the end, there is a matching w. writeEndDocument (); w. writeStartElement ("SpotList"); w. writeAttributeString ("xmlns: xsi", "http: www.w3.org/2001/XMLSchema-instance"); // attributes of the SpotList node w. writeAttributeString ("xmlns: xsd", "http: www.w3.org/2001/XMLSchema"); // SpotList node attribute, final effect:
 
  
W. writeStartElement ("Items"); w. writeElementString ("Name", myPoints [j]. name); w. writeElementString ("Caption", myPoints [j]. caption); w. writeElementString ("Addr", myPoints [j]. addr); w. writeElementString ("Phone", myPoints [j]. phone); w. writeStartElement ("Intro"); // The final effect is as follows:
  相关内容
  W. writeCData (myPoints [j]. intro); w. writeEndElement (); w. writeEndElement (); w. writeEndElement (); w. writeEndDocument (); w. close (); // complete the output of the xml file, Close
 

The above is the content of the XML file generated using XmlTextWriter. For more information, see PHP Chinese website (www.php1.cn )!

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.