Program works, but no data being displayed
Hi all, I am doing a server-side application. When user click on the "Parse the uploaded file" button in an html page, it will then call the DisplayBook.asp ... in this function, it will read a text file called book.txt and display the data on the html browser. However, it return with no data read. Meaning, if there is no data, it will display a mesage "Book information not specified". But, in my book.txt file, it has data like this:-
================================================
Professional XML Wrox Press March 2000
800 1861001576 49.99
This book is a definitive, practical guide to XML.
AKevin Williams
ASteven Millar
ANikola Ozu
CXML
CInternet Development
CInternet Design
=================================================
The output should be like:-
Book Information
Title: Professional XML
Publisher: Wrox Press
Published Date: March 2000
Abstract: This book is a definitive, practical guide to XML.
Pages: 800
ISBN: 1861001576
Price: 49.99
Authors
Kevin Williams
Steven Millar
Nikola Ozu
Category
XML
Internet Development
CInternet Design
===========================================
What did I missed out so taht the displaybook.asp didn't read the data in book.txt? All my files are store in "http:\\localhost\xml\book\chapter5_serverside \ ... "
My displaybook.asp code as follow (it works fine) ...
============================================
<%@ Language=VBScript @%>
<HTML>
<HEAD>
<TITLE>Thank you for submitting your book information!</TITLE>
<SCRIPT>
function renderElements()
{
bookInfo.innerHTML = docBook.transformNode(bookXSL.documentElement);
authorTable.innerHTML = docBook.transformNode(authorXSL.documentElement);
categoryTable.innerHTML = docBook.transformNode(categoryXSL.documentElement) ;
}
</SCRIPT>
<%
Sub AddElementToParent (domBook, elemParent, sChild, sValue)
Dim elemSubelement
Dim textSubelement
Set elemSubelement = domBook.CreateElement(sChild)
Set textSubelement = domBook.CreateTextNode(sValue)
elemSubelement.appendChild(textSubelement)
elemParent.appendChild(elemSubelement)
Set elemSubelement = Nothing
Set elemSubelement = Nothing
End Sub
Sub WriteNodeXML (nodeTarget)
Dim i
If nodeTarget.NodeType = 1 Then
'Element
Response.Write "<" & nodeTarget.tagName & ">"
For i = 0 to nodeTarget.childNodes.Length - 1
WriteNodeXML nodeTarget.childNodes.item(i)
Next
Response.Write "</" &nodeTarget.tagName & ">"
ElseIf nodeTarget.NodeType = 3 Then
'Text Node
Response.Write nodeTarget.data
End If
End Sub
%>
<xml id="docBook">
<%
Dim fileInvoice
Dim tsInvoice
Dim domInvoice
Dim elemInvoice
Dim elemLineItem
Dim sFilename
Dim sPath
Dim sLine
Dim sWork
Const ForReading = 1
sFilename = "C:\Inetpub\wwwroot\XML\Book\Chapter5_ServerSide\b ook.txt"
'sFilename = "C:\book.txt"
'create the instance of the DOM and the root Book element
Set domBook = CreateObject("Microsoft.XMLDOM")
domBook.async = "false"
Set elemBook = domBook.CreateElement("Book")
domBook.appendChild elemBook
'open the file
Set fileBook = Server.CreateObject("Scripting.FileSystemObject")
Set tsBook = fileBook.OpenTextFile(sFilename, ForReading)
'process the title and publisher line
sLine = tsBook.ReadLine
sWork = Trim(Mid(sLine, 1, 30)) 'Title
AddElementToParent domBook, elemBook, "Title", sWork
sWork = Trim(Mid(sLine, 31, 20)) 'Publisher
AddElementToParent domBook, elemBook, "Publisher", sWork
sWork = Trim(Mid(sLine, 51, 20)) 'Title
AddElementToParent domBook, elemBook, "PubDate", sWork
'process the number of pages, ISBN, and price line
sLine = tsBook.ReadLine
sWork = Trim(Mid(sLine, 1, 10)) 'Number of pages
AddElementToParent domBook, elemBook, "Pages", sWork
sWork = Trim(Mid(sLine, 11, 13)) 'ISBN
AddElementToParent domBook, elemBook, "ISBN", sWork
sWork = Trim(Mid(sLine, 24, 10)) 'Price
AddElementToParent domBook, elemBook, "Price", sWork
'process the abstract line
sLine = tsBook.ReadLine
AddElementToParent domBook, elemBook, "Abstract", sLine
Set elemRecSubjCategories = domBook.CreateElement("RecSubjCategories")
Set elemAuthors = domBook.CreateElement("Authors")
elemBook.appendChild(elemRecSubjCategories)
elemBook.appendChild(elemAuthors)
While Not tsBook.AtEndOfStream
sLine = tsBook.ReadLine
If Left(sLine, 1) = "A" Then
AddElementToParent domBook, elemAuthors, "Author", Mid(sLine, 2)
Else
AddElementToParent domBook, elemRecSubjCategories, "Category", Mid(sLine, 2)
End If
Wend
tsBook.Close
WriteNodeXML elemBook
'and clear our objects
Set fileBook = Nothing
Set tsBook = Nothing
Set domBook = Nothing
Set elemBook = Nothing
Set elemAuthor = Nothing
Set elemRecSubjCategories = Nothing
Set elemAuthors = Nothing
%>
</xml>
<xml id="bookXSL">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" indent="yes"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="/book/Title[. != '']">
<table border="0" cellpadding="1">
<tr>
<td>Title:</td>
<td><xsl:value-of select="/book/Title"/></td>
</tr>
<tr>
<td>Publisher:</td>
<td><xsl:value-of select="/book/Publisher"/></td>
</tr>
<tr>
<td>Published Date:</td>
<td><xsl:value-of select="/book/PubDate"/></td>
</tr>
<tr>
<td>Abstract:</td>
<td><xsl:value-of select="/book/Abstract"/></td>
</tr>
<tr>
<td>Pages:</td>
<td><xsl:value-of select="/book/Pages"/></td>
</tr>
<tr>
<td>ISBN:</td>
<td><xsl:value-of select="/book/ISBN"/></td>
</tr>
<tr>
<td>Price:</td>
<td><xsl:value-of select="/book/Price"/></td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<p>Book Information not yet specified.</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</xml>
<xml id="authorXSL">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" indent="yes"/>
<xsl:template match="/">
<table border="0" cellpadding="1">
<tr>
<td><strong>Authors</strong></td>
</tr>
<xsl:for-each select="/book/authors/author">
<tr>
<td><xsl:value-of select="text()"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
</xml>
<xml id="categoryXSL">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" indent="yes"/>
<xsl:template match="/">
<table border="0" cellpadding="1">
<tr>
<td><strong>Categories</strong></td>
</tr>
<xsl:for-each select="/book/recSubjCategories/category">
<tr>
<td><xsl:value-of select="text()"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
</xml>
</HEAD>
<BODY onload="renderElements()">
<h2>Book information</h2>
<p><div id="bookInfo"></div></p>
<p><div id="authorTable"></div></p>
<p><div id="categoryTable"></div></p>
</BODY>
</HTML>
|