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 )!