by Mike G (7 Submissions)
Category: Internet/HTML
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 23rd August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Read and Write xml Files
' Copyright ©2001 Mike G --> IvbNET.COM
' All Rights Reserved, http://www.ivbnet.com
' EMAIL : [email protected]
' ------------------------------------------------------------
' You are free to use this code within your own applications,
' but you are forbidden from selling or distributing this
' source code without prior written consent.
' ------------------------------------------------------------
Private Sub cmdWite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdWite.Click
Call Write_XML()
End Sub
Private Sub Write_XML()
Dim XMLobj As Xml.XmlTextWriter
Dim enc As New System.[Text].UnicodeEncoding()
XMLobj = New Xml.XmlTextWriter("C:\test.xml", enc)
XMLobj.Formatting = Xml.Formatting.Indented
XMLobj.Indentation = 3
XMLobj.WriteStartDocument()
XMLobj.WriteStartElement("Books")
XMLobj.WriteStartElement("Book")
XMLobj.WriteAttributeString("ISBN", "100000000")
XMLobj.WriteAttributeString("Title", "IvbNET.com")
XMLobj.WriteAttributeString("Price", "50.00")
XMLobj.WriteEndElement()
XMLobj.WriteEndElement()
XMLobj.Close()
MsgBox("Done", MsgBoxStyle.Exclamation, "XML")
End Sub
Private Sub cmdRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRead.Click
Call Read_XML()
End Sub
Private Sub Read_XML()
Dim XMLReader As Xml.XmlReader
XMLReader = New Xml.XmlTextReader("C:\test.xml")
While XMLReader.Read
Select Case XMLReader.NodeType
Case Xml.XmlNodeType.Element
Debug.WriteLine(XMLReader.Name)
If XMLReader.AttributeCount > 0 Then
While XMLReader.MoveToNextAttribute
Debug.WriteLine(XMLReader.Name & "->" & XMLReader.Value)
End While
End If
Case Xml.XmlNodeType.Text
Debug.WriteLine(XMLReader.Value)
Case Xml.XmlNodeType.Comment
Debug.WriteLine(XMLReader.Value)
End Select
End While
XMLReader.Close()
MsgBox("Done", MsgBoxStyle.Exclamation, "XML")
End Sub
End Class