Use XMLTextWriter to create XML file (VB.net) : XMLTextWriter « XML « ASP.NET Tutorial






<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>

<script runat=server>
   sub Page_Load(Sender as Object, e as EventArgs)
      dim writer as XMLTextWriter
         
      try
         writer = new XMLTextWriter(Server.MapPath("Data.xml"), nothing)
         
         writer.WriteStartDocument
         writer.Formatting = Formatting.Indented
         writer.Indentation = 3
         writer.WriteStartElement("bookstore")
         writer.WriteStartElement("book")
         writer.WriteAttributeString("genre", "history")
         writer.WriteElementString("title", "my title")
         writer.WriteElementString("price","6.99")
         writer.WriteStartElement("author")
         writer.WriteElementString("first-name","M")
         writer.WriteEndElement()
         writer.WriteEndElement()
         writer.WriteEndElement()
         writer.Flush
      catch ex as Exception
         Response.Write("Error accessing XML file")
      finally
         writer.Close
         Response.Write("Finished processing")
      end try
   end sub
</script>

<html><body>

</body></html>








25.16.XMLTextWriter
25.16.1.Use XMLTextWriter to create XML file (VB.net)
25.16.2.Use XmlTextWriter to create XML document, then use XmlTextReader to read it back