XMLPage.zip
bin
XMLRead.dll
guestbook.xsl
src
|
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
Public Class XMLReader
Inherits System.Web.UI.Page
Public xmlDoc As New XmlDocument
Public xslDoc As New Xml.Xsl.XslTransform
Public pageSize As String = 5
Public Sub initXml()
Dim xmlDocStr = Request.PhysicalApplicationPath & "guestbook.xml"
Dim xslDocStr = Request.PhysicalApplicationPath & "guestbook.xsl"
' Load the dom
If File.Exists(xmlDocStr) Then
Try
xmlDoc.Load(xmlDocStr)
Catch e As Exception
Response.Write("<B>Error in XML File:</b> " & e.Message)
Response.End()
End Try
Else
xmlDoc.LoadXml("<guestbook></guestbook>")
End If
' Load the xsl
If File.Exists(xslDocStr) Then
Try
xslDoc.Load(xslDocStr)
Catch e As Exception
Response.Write("<B>Error in XSL File:</b> " & e.Message)
Response.End()
End Try
Else
Response.Write("<B>Error in XSL File:</b> file not found.")
Response.End()
End If
End Sub
Public Function buildPageHTML()
Dim counter = 1
Dim pagelink = ""
Dim allNodes As XmlNodeList = xmlDoc.SelectNodes("//guestbook/entry")
Dim pages As Integer = allNodes.Count / pageSize
If pages <> Int(pages) Then pages = Int(pages) + 1
For counter = 1 To pages + 1
pagelink &= "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?page=" & counter & """>" & counter & "</a> "
Next
Return pagelink
End Function
Public Function Display()
Dim currentPage = Request.QueryString("page")
Dim xsltParams As New XsltArgumentList
If currentPage = 0 Then currentPage = 1
If currentPage - 1 = 0 Then
xsltParams.AddParam("start", "", 1)
Else
xsltParams.AddParam("start", "", ((currentPage - 1) * pageSize) + 1)
End If
xsltParams.AddParam("end", "", ((currentPage - 1) * pageSize) + pageSize)
xsltParams.AddParam("link", "", buildPageHTML)
Try
xslDoc.Transform(xmlDoc, xsltParams, Response.OutputStream, Nothing)
Catch e As Exception
Response.Write(e.Message)
End Try
End Function
Private Sub XMLReader_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
initXml()
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I started programming for fun when I was about 10 on an Franklin Ace 1000.
I still do it just for fun but it has gotten me a few jobs over the years. More then I can say for my Microsoft Certifications.
The way I learned was by example, now its time to give back to the next generation of coders.