dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersAnu George
NareshGodera
N. KUMAR
Naveen
Mahesh
Shesh Kumar Mishra
Pawan Awasthi
saranya
raju
Anil Kumar Pandey
sudheera
More...




Resources » Code Snippets » XML


Read and Write XML files using VB.NET.


Posted Date:     Category: XML    Rating: 1 out of 5
Author: Member Level: Gold    Points: 10


This is a VB.NET sample code to read and Write XML files


' ------------------------------------------------------------
' Copyright ©2001 Mike G --> IvbNET.COM
' All Rights Reserved, http://www.ivbnet.com
' EMAIL : webmaster@ivbnet.com
' ------------------------------------------------------------
' 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






Did you like this resource? Share it with your friends and show your love!





Responses to "Read and Write XML files using VB.NET."
Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Adding multiple users using Web.config file in Forms Authentication
    Previous Resource: How to Generate a DataSet from XML File using C#
    Return to Resources
    Post New Resource
    Category: XML


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)

    My Profile

    Active Members
    TodayLast 7 Daysmore...


    Awards & Gifts


    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.