Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - 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 
Actuate Whitepapers 
VeriSign Whitepapers 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Reading and Transforming XML Documents using Visual Basic 2005 - Transforming an XML document to HTML using XSLT with VB 2005


    (Page 5 of 6 )

    XSL stands for eXtensible Stylesheet Language. It is a language used to design and apply style sheets especially for XML documents. Originally the research was started to provide style sheet technology to XML using XSL, but we finally ended up with three more divisions of XSL. So XSL now consists of three parts, namely XSLT, XPath and XSL-FO.

    XSLT is a language for transforming XML documents (even today, several programmers say XSL when they really mean XSLT). XPath is a language to filter, search or sort information available in XML documents. XSL-FO is a language for formatting XML documents. In this article we mainly focus on XSLT, which stands for XSL Transformations.

    XSLT can also be used to transform an XML document to another XML document (it need not be used only for HTML documents). Another beauty of XSLT is that it internally works using XPath language. We can even conclude that “The more we learn about XPath, the better XSLT we can design.” Although the sections from this point forward mainly focus on XSL, I suggest you go through the fundamentals of the XPath language for better understanding (but it's not necessary for this article).

    Before transforming an XML document, we need to define the XSLT which emits HTML based on the structure of our existing XML document.  The following is the XSLT needed to emit the TABLE structure of HTML:

    <?xml version="1.0" encoding="UTF-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform">

          <xsl:template match="/">

                <html>

                      <body>

                            <table width="50%" cellspacing="0" cellpadding="0" style="font-
    family:verdana;font-size:X-Small
    " border="1">

                                  <tr bgcolor="#336699">

                                        <th align="left">

                                              <font color="White">ID</font>

                                        </th>

                                        <th align="left">

                                              <font color="White">Name</font>

                                        </th>

                                        <th align="right">

                                              <font color="White">Salary</font>

                                        </th>

                                        <th align="right">

                                              <font color="White">Deptno</font>

                                        </th>

                                  </tr>

                                        <tr>

                                              <td align="left">

                                                    <xsl:value-
    of
     select="Employees/Employee/Empno"/>

                                              </td>

                                              <td align="left">

                                                    <xsl:value-
    of
     select="Employees/Employee/Ename"/>

                                              </td>

                                              <td align="right">

                                                    <xsl:value-
    of
     select="Employees/Employee/Sal"/>

                                              </td>

                                              <td align="right">

                                                    <xsl:value-
    of
     select="Employees/Employee/Deptno"/>

                                              </td>

                                        </tr>

                            </table>

                      </body>

                </html>

          </xsl:template>

    </xsl:stylesheet>

    The following code transforms the XML document to the above XSLT:

      Private Sub btnSampleXSLT_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles btnSampleXSLT.Click

            Dim docXML As New XmlDocument

            docXML.Load(Application.ExecutablePath &
    "......Employee.xml")

            Dim xslt As New Xsl.XslCompiledTransform

            xslt.Load(Application.ExecutablePath &
    "......Employee.xslt")

            Dim sb As New System.Text.StringBuilder

            Dim s As New IO.StringWriter(sb)

            xslt.Transform(docXML, New XmlTextWriter(s))

            s.Close()

            Me.TextBox1.Text = sb.ToString

        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

    - 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 ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic





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