Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 14th, 2003, 01:44 PM
Authorized User
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
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

Kevin Williams
Steven Millar
Nikola Ozu

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 @%>
       <TITLE>Thank you for submitting your book information!</TITLE>

function renderElements()
    bookInfo.innerHTML = docBook.transformNode(bookXSL.documentElement);
    authorTable.innerHTML = docBook.transformNode(authorXSL.documentElement);
    categoryTable.innerHTML = docBook.transformNode(categoryXSL.documentElement) ;

    Sub AddElementToParent (domBook, elemParent, sChild, sValue)
       Dim elemSubelement
       Dim textSubelement

       Set elemSubelement = domBook.CreateElement(sChild)
       Set textSubelement = domBook.CreateTextNode(sValue)

       Set elemSubelement = Nothing
       Set elemSubelement = Nothing
    End Sub

    Sub WriteNodeXML (nodeTarget)
       Dim i

       If nodeTarget.NodeType = 1 Then
           Response.Write "<" & nodeTarget.tagName & ">"
           For i = 0 to nodeTarget.childNodes.Length - 1
               WriteNodeXML nodeTarget.childNodes.item(i)
           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")


          While Not tsBook.AtEndOfStream
              sLine = tsBook.ReadLine
              If Left(sLine, 1) = "A" Then
                  AddElementToParent domBook, elemAuthors, "Author", Mid(sLine, 2)
                  AddElementToParent domBook, elemRecSubjCategories, "Category", Mid(sLine, 2)
              End If

          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 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:when test="/book/Title[. != '']">
                               <table border="0" cellpadding="1">
                                         <td><xsl:value-of select="/book/Title"/></td>
                                         <td><xsl:value-of select="/book/Publisher"/></td>
                                         <td>Published Date:</td>
                                         <td><xsl:value-of select="/book/PubDate"/></td>
                                         <td><xsl:value-of select="/book/Abstract"/></td>
                                         <td><xsl:value-of select="/book/Pages"/></td>
                                         <td><xsl:value-of select="/book/ISBN"/></td>
                                         <td><xsl:value-of select="/book/Price"/></td>
                               <p>Book Information not yet specified.</p>

    <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">
              <xsl:for-each select="/book/authors/author">
                        <td><xsl:value-of select="text()"/></td>

    <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">
               <xsl:for-each select="/book/recSubjCategories/category">
                        <td><xsl:value-of select="text()"/></td>

 <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>

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generic Q on data bound program Minos Visual Basic 2005 Basics 1 November 9th, 2006 12:28 PM
data not being displayed goingmad SQL Server ASP 8 March 27th, 2006 03:36 AM
Data Binding works but why no value? fukchai2000 C# 0 March 21st, 2006 05:59 AM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.