• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Can't get XML code to work

OK - bear with me..

I purchased Teach Yourself ASP in 24 hours and am trying to implement the example in chapter 24 for a simple shopping bag. I haven't changed anything other than the DB name and connection info.

To see the example go to: http://www.asp24h.com/  and click on try the examples on-line (chapter 24) You can also download the bag.asp page from here.

Anyway - I changed my DB to have exactly the same field names and have implemented it at the following test address:

http://cobweb-corner.com/crossstitchscart.htm

Note: This is only set up with the KEYWORD SEARCH - the category search doesn't work. Type  angel  in the category search and then press ENTER.  Click on any ADD TO CART LINK...

Following error appears:
Response object error 'ASP 0185 : 80020003'

Missing Default Property

/bag.asp, line 0

A default property was not found for the object.


This happens during the PrintBag subroutine - here is the code:

Sub PrintBag(BagItems)
     Out "<FORM METHOD=""POST"" ACTION="""
     Out Request.ServerVariables("SCRIPT_NAME") & """>"
     Out "<TABLE><TR><TH>Units</TH><TH COLSPAN=2>"
     Out "Product</TH><TH>Unit Price</TH><TH>Price</TH>"
     Out "</TR>" & vbCrLf
     For Each item In BagItems.childNodes
          out "Got Here"
          Out item.attributes.getNamedItem("productid")
          Out item.attributes.getNamedItem("productname")
          Out item.attributes.getNamedItem("quantityperunit")
          Out item.attributes.getNamedItem("unitprice")



          Out "<TR><TD><input type=""TEXT"" name=""Qty"
          Out item.attributes.getNamedItem("productid")
          Out """ VALUE=""" & item.text & """ SIZE=""3"">"
          Out "<TD>" & item.attributes.getNamedItem("productname")
          Out "</TD><TD>" & item.attributes.getNamedItem("quantityperunit") & "</TD>"
          nUnitPrice = item.attributes.getNamedItem("unitprice")
          nSubTotal = item.text * nUnitPrice
          nTotal = nTotal + nSubTotal
          Out "<TD>" & FormatCurrency(nUnitPrice) & "</TD>"
          Out "<TD><B>" & FormatCurrency(nSubTotal) & "</B></TD>"
          Out "</TR>" & vbCRLF
     Next
     Out "<TR><TD COLSPAN=5><HR></TD></TR>"
     Out "<TR><TD COLSPAN=3></TD><TD><B>Total:</B></TD>"
     Out "<TD><B>" & FormatCurrency(nTotal) & "</B></TD></TR>" & vbCrLf
     Out "<TR><TD COLSPAN=5 ALIGN=""RIGHT"">"
     Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Shop for more"">&nbsp;"
     Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Recalculate"">&nbsp;"
     Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Check out"">"
     Out "</TD></TR></TABLE></FORM>"
End Sub


I'm CLUELESS - I did debug the routines that load the bag - the DB is being opened and the correct fields returned and they are loaded into an array with the .GETROWS() method - after that ?????

PLEASE HELP
Carla
0
cekman
Asked:
cekman
  • 11
  • 2
1 Solution
 
b1xml2Commented:
it is
item.attributes.getNamedItem("productname").nodeValue
and NOT just
item.attributes.getNamedItem("productname")

item.attributes.getNamedItem returns a IXMLDOMNode | IXMLDOMAttribute . There is no default property for item.attributes.getNamedItem("productname")
0
 
b1xml2Commented:
this applies to all your calls via the getNamedItem() method. You need to supply the nodeValue property to get the value.
0
 
b1xml2Commented:
bad bad code...
Please add to the top of the page:
<%@language="VBScript"%>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
b1xml2Commented:
Next, the connection settings are pretty wrong

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=your_password;"
objConn.Open strConnection

This is for a Microsoft SQL Server Connection as an example.
0
 
b1xml2Commented:
This works for me.

<%@language="VBScript"%>
<% Response.Buffer = True %>
<html>
<head>
      <title>Implementing the Shopping Bag</title>
</head>
<body bgcolor="#ffffff">
<%
On Error Resume Next
' get or create the bag
Set BagItems = LoadXMLBag()

' add or modify products
If Request.ServerVariables("CONTENT_LENGTH") > 0 Then
      Select Case Trim(Request.Form("DO"))
            Case "Shop for more"
                  Response.Redirect "products.asp"
                  Response.End
            Case "Recalculate"
                  RecalcBag BagItems
            Case "Check out"
                  ' recalculate and then redirect to checkout
      End Select
Else
      ' products are added using the query string
      nProductId = Trim(Request.QueryString("id"))
      AddtlProduct nProductId, BagItems
End If

Session("BagItems") = BagItems.XML

If BagItems.hasChildNodes Then
      PrintBag BagItems
Else
      Response.Write "Sorry, you have no items in your bag!"
End If
%>
</body>
</html>

<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
Function LoadXMLBag()
      Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM")
      If Not IsEmpty(Session("BagItems")) Then
            XMLDoc.loadXML CStr(Session("BagItems"))
            Set BagItems = XMLDoc.documentElement
      Else
            Set BagItems = XMLDoc.createElement("BagItems")
            Set XMLDoc.documentElement = BagItems
      End If
      Set LoadXMLBag = BagItems
End Function

Sub AddtlProduct(nProductId, BagItems)
      bValid = True
      
      If "" = nProductId Or Not IsNumeric(nProductId) Then
            bValid = False
      Else
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=mypassword;"
            Set objRS = Server.CreateObject("ADODB.Recordset")
            Set objRS.ActiveConnection = objConn
            objRS.Open "SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice FROM Products WHERE ProductId=" & nProductId
            If objRS.EOF And objRS.BOF Then
                  bValid = False
            Else
                  avarProduct = objRS.GetRows()
            End If
            objConn.Close
            Set objRS = Nothing
            Set objConn = Nothing
      End If
      
      ' if the product was ok, add it to the bag
      If bValid Then
            AddProductToBag avarProduct, BagItems
      End If
End Sub

Sub AddProductToBag(avarProduct, BagItems)
      Set XMLDoc = BagItems.ownerDocument
      Set nodeFind = BagItems.selectNodes("product[@productid=""" & nProductId & """]")
      If Not nodeFind.length > 0 Then
            Set product = XMLDoc.createElement("product")
            Set attr = XMLDoc.createAttribute("productid")
            attr.Text = avarProduct(0,0)
            product.attributes.setNamedItem(attr)
            Set attr = XMLDoc.createAttribute("productname")
            attr.Text = Server.HtmlEncode(avarProduct(1,0))
            product.attributes.setNamedItem(attr)
            Set attr = XMLDoc.createAttribute("quantityperunit")
            attr.Text = Server.HtmlEncode(avarProduct(2,0))
            product.attributes.setNamedItem(attr)
            Set attr = XMLDoc.createAttribute("unitprice")
            attr.Text = avarProduct(3,0)
            product.attributes.setNamedItem(attr)
            product.text = "1"
            BagItems.appendChild(product)
      End If
End Sub

Sub Out(strOut)
      Response.Write strOut
End Sub

Sub PrintBag(BagItems)
      Out "<FORM METHOD=""POST"" ACTION="""
      Out Request.ServerVariables("SCRIPT_NAME") & """>"
      Out "<TABLE><TR><TH>Units</TH><TH COLSPAN=2>"
      Out "Product</TH><TH>Unit Price</TH><TH>Price</TH>"
      Out "</TR>" & vbCrLf
      For Each item In BagItems.childNodes
            Out "<TR><TD><input type=""TEXT"" name=""Qty"
            Out item.attributes.getNamedItem("productid").nodeValue
            Out """ VALUE=""" & item.text & """ SIZE=""3"">"
            Out "<TD>" & item.attributes.getNamedItem("productname").nodeValue
            Out "</TD><TD>" & item.attributes.getNamedItem("quantityperunit").nodeValue & "</TD>"
            nUnitPrice = item.attributes.getNamedItem("unitprice").nodeValue
            nSubTotal = item.text * nUnitPrice
            nTotal = nTotal + nSubTotal
            Out "<TD>" & FormatCurrency(nUnitPrice) & "</TD>"
            Out "<TD><B>" & FormatCurrency(nSubTotal) & "</B></TD>"
            Out "</TR>" & vbCRLF
      Next
      Out "<TR><TD COLSPAN=5><HR></TD></TR>"
      Out "<TR><TD COLSPAN=3></TD><TD><B>Total:</B></TD>"
      Out "<TD><B>" & FormatCurrency(nTotal) & "</B></TD></TR>" & vbCrLf
      Out "<TR><TD COLSPAN=5 ALIGN=""RIGHT"">"
      Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Shop for more"">&nbsp;"
      Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Recalculate"">&nbsp;"
      Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Check out"">"
      Out "</TD></TR></TABLE></FORM>"
End Sub

Sub RecalcBag(BagItems)
      For Each item in BagItems.childNodes
            nQty = Trim(Request.Form("Qty" & item.attributes.getNamedItem("productid").nodeValue))
            If "" <> nQty And IsNumeric(nQty) Then
                  If nQty < 1 Then
                        BagItems.removeChild item
                  Else
                        item.text = nQty
                  End If
            End If
      Next
End Sub
</SCRIPT>
0
 
b1xml2Commented:
The Cause Of The Problem
========================
1. Failure to use the .nodeValue as I had suspected initially.
2. Plus the ConnectionString for the ADO Connection Object should be changed accordingly.

If it is MSSQL Server:
Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=mypassword;
0
 
cekmanAuthor Commented:
Thank You!

You can check it out at http://cobweb-corner.com/crossstitchscart.htm  - using just the keyword search feature.

This is exactly what I need. Right now my customers must write down what they want. I'm not ready to have full on-line payment - as I usually need to verify my inventory/condition etc.

Next I want to be able to have them click on the Checkout button and have them fill in my order entry form and have it email me their shopping bag - this isn't covered in the book. Which topic under EE should I post that question? If you're able to help me let me know and I'll let you know when I post the question - I've got LOTS of points to use up! LOL

Thanks again!
Carla
0
 
b1xml2Commented:
post here since you are using XML.
0
 
b1xml2Commented:
here = XML Topic Area
0
 
b1xml2Commented:
Are you using Access or MS-SQL Server?
0
 
cekmanAuthor Commented:
I'm using Access.
0
 
b1xml2Commented:
have you got SMTP Server working? That will allow you to use CDONTS to send email to your account. If the SMTP Server Service is not running, you would not be able to automate the sending of mail to your email account.
0
 
b1xml2Commented:
that portion about sending email via ASP can be posted in the ASP Topic Area, if you want.

The other portion of what to show on the checkout and what is to be put in your email can be placed here.

But for completeness, you could post a single question in either ASP or XML.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 11
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now