Use XmlTextWriter to generate an XML file

Source: Internet
Author: User
Project compatibility requires the generation of a series of XML files, which summarizes the basic XML file generation method XmlTextWriterw = newXmlTextWriter (C: \ XML file name. xml, Encoding. unicode); // Encoding. unicode is the encoding format used to generate XML files, which can be combined with the output:

Project compatibility requires generating a series of XML files, which 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"); // SpotList node attributes
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

 

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.