VB.Net - SPLessons

VB.Net XML Processing

Home > Lesson > Chapter 29
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

VB.Net XML Processing

VB.Net XML Processing

shape Description

XML stands for Extensible Markup Language and it will have separate file like HTML, SGML.XML is the open source and utilized to create common information formats and share both format and the information on the World Wide Web.XML will have two parsing API such as Document object model(DOM) and Simple API for XML(SAX).SAX is an element driven web algorthim for parsing XML reports, with an API created by the XML-DEV mailing list. SAX gives a component to perusing information from a XML report that is a contrasting option to that gave by the Document Object Model (DOM).

shape Example

Following is an example which describes more about the XML file in VB.net . [vbnet]Imports System.Xml Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Set the caption bar text of the form. Me.Text = "SPLessons.com" End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim xws As XmlWriterSettings = New XmlWriterSettings() xws.Indent = True xws.NewLineOnAttributes = True Dim xw As XmlWriter = XmlWriter.Create("authors.xml", xws) xw.WriteStartDocument() xw.WriteStartElement("Authors") xw.WriteStartElement("author") xw.WriteAttributeString("code", "1") xw.WriteElementString("fname", "Zara") xw.WriteElementString("lname", "Ali") xw.WriteEndElement() xw.WriteStartElement("author") xw.WriteAttributeString("code", "2") xw.WriteElementString("fname", "Priya") xw.WriteElementString("lname", "Sharma") xw.WriteEndElement() xw.WriteStartElement("author") xw.WriteAttributeString("code", "3") xw.WriteElementString("fname", "Anshuman") xw.WriteElementString("lname", "Mohan") xw.WriteEndElement() xw.WriteStartElement("author") xw.WriteAttributeString("code", "4") xw.WriteElementString("fname", "Bibhuti") xw.WriteElementString("lname", "Banerjee") xw.WriteEndElement() xw.WriteStartElement("author") xw.WriteAttributeString("code", "5") xw.WriteElementString("fname", "Riyan") xw.WriteElementString("lname", "Sengupta") xw.WriteEndElement() xw.WriteEndElement() xw.WriteEndDocument() xw.Flush() xw.Close() WebBrowser1.Url = New Uri(AppDomain.CurrentDomain.BaseDirectory + "authors.xml") End Sub End Class[/vbnet] Output When compile the code following is the form will be displayed. When user click on the button following is the result will be displayed.

Summary

shape Points

  • XML is same like HTML.
  • SAX stands for Simple API for XML.
  • DOM stands for Document object model.
  • SAX can not process the information as fast than DOM.