Solved

Can't get XML code to work

Posted on 2002-05-26
13
185 Views
Last Modified: 2008-02-01
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
Comment
Question by:cekman
  • 11
  • 2
13 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035404
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
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035405
this applies to all your calls via the getNamedItem() method. You need to supply the nodeValue property to get the value.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035410
bad bad code...
Please add to the top of the page:
<%@language="VBScript"%>
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035412
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
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035416
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
 
LVL 23

Accepted Solution

by:
b1xml2 earned 300 total points
ID: 7035417
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 5

Author Comment

by:cekman
ID: 7035447
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
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035455
post here since you are using XML.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035464
here = XML Topic Area
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035496
Are you using Access or MS-SQL Server?
0
 
LVL 5

Author Comment

by:cekman
ID: 7035548
I'm using Access.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035553
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
 
LVL 23

Expert Comment

by:b1xml2
ID: 7035557
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now