jhylands

Write to XML

Jan 3rd, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.31 KB | None | 0 0
  1. Imports System
  2. Imports System.Xml
  3.  
  4. Module Module1
  5.  
  6.     Sub Main()
  7.         Dim settings As New XmlWriterSettings()
  8.         settings.Indent = True
  9.  
  10.         ' Initialize the XmlWriter.
  11.         Dim XmlWrt As XmlWriter = XmlWriter.Create("C:\Users\james\Desktop\MyName.xml", settings)
  12.  
  13.         With XmlWrt
  14.  
  15.             ' Write the Xml declaration.
  16.             .WriteStartDocument()
  17.  
  18.             ' Write a comment.
  19.             .WriteComment("XML Database.")
  20.  
  21.             ' Write the root element.
  22.             .WriteStartElement("Data")
  23.  
  24.             ' Start our first person.
  25.             .WriteStartElement("Person")
  26.  
  27.             ' The person nodes.
  28.  
  29.             .WriteStartElement("Name")
  30.             .WriteString("James")
  31.             .WriteEndElement()
  32.  
  33.             .WriteStartElement("Email")
  34.             .WriteString("[email protected]")
  35.             .WriteEndElement()
  36.  
  37.             .WriteStartElement("Tel")
  38.             .WriteString("111")
  39.             .WriteEndElement()
  40.  
  41.             .WriteStartElement("Notes")
  42.             .WriteString("bo")
  43.             .WriteEndElement()
  44.  
  45.             ' The end of this person.
  46.             .WriteEndElement()
  47.  
  48.             ' Close the XmlTextWriter.
  49.             .WriteEndDocument()
  50.             .Close()
  51.  
  52.         End With
  53.  
  54.     End Sub
  55.  
  56. End Module
Advertisement
Add Comment
Please, Sign In to add comment