Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Reading and Transforming XML Documents usi...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Reading and Transforming XML Documents using Visual Basic 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 12
    2006-11-21

    Table of Contents:
  • Reading and Transforming XML Documents using Visual Basic 2005
  • Reading the tags in an XML document using XMLReader
  • Reading the values (or text) of XML tags in an XML document using XMLReader
  • Reading an XML string using XMLReader
  • Transforming an XML document to HTML using XSLT with VB 2005
  • Transformation using XSLT for multiple XML nodes of the same criteria

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Reading and Transforming XML Documents using Visual Basic 2005 - Reading the values (or text) of XML tags in an XML document using XMLReader


    (Page 3 of 6 )

    In the previous section, we read only the tags available in an XML document. In this section, we will read the values and also the related tags along with them.  First of all, let us concentrate on reading values. Consider the following code:

    PrivateSub btnShowValues_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowValues.Click

            Me.TextBox1.Text = ""

            Dim rd As XmlReader = XmlReader.Create(Application.ExecutablePath & "......Employee.xml")

            While rd.Read

                If rd.NodeType = XmlNodeType.Text Then

                    Me.TextBox1.Text &= rd.ReadString & ControlChars.NewLine

                End If

            End While

            rd.Close()

        End Sub

    You can observe that I am comparing with the “text” type of SML node to retrieve the values available in XML document.  You can also observe that I am using the “ReadString” method to read the value.

    Finally, the following code retrieves each and every tag along with its name, text, and so forth:

    PrivateSub btnShowXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowXML.Click

            Me.TextBox1.Text = ""

            Dim rd As XmlReader = XmlReader.Create(Application.ExecutablePath & "......Employee.xml")

            While rd.Read

                Select Case rd.NodeType

                    Case XmlNodeType.Element

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<{0}>", rd.Name) & ControlChars.NewLine

                    Case XmlNodeType.Text

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format(rd.Value) & ControlChars.NewLine

                    Case XmlNodeType.CDATA

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<![CDATA[{0}]]>", rd.Value) & ControlChars.NewLine

                    Case XmlNodeType.ProcessingInstruction

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<?{0} {1}?>", rd.Name, rd.Value) & ControlChars.NewLine

                    Case XmlNodeType.Comment

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<!--{0}-->", rd.Value) & ControlChars.NewLine

                    Case XmlNodeType.XmlDeclaration

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<?xml version='1.0'?>") & ControlChars.NewLine

                    Case XmlNodeType.Document

                    Case XmlNodeType.DocumentType

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("<!DOCTYPE {0} [{1}]", rd.Name, rd.Value) & ControlChars.NewLine

                    Case XmlNodeType.EntityReference

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format(rd.Name) & ControlChars.NewLine

                    Case XmlNodeType.EndElement

                        Me.TextBox1.Text &= Space(rd.Depth * 4) & String.Format("</{0}>", rd.Name) & ControlChars.NewLine

                End Select

            End While

            rd.Close()

        End Sub

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! this is the article which helps you to parse through XML documents using...
     

    VISUAL BASIC.NET ARTICLES

    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway