Altova Mailing List Archives


Re: Object required

From: "Roland Hall" <nobody@------->
To: NULL
Date: 1/11/2005 8:26:00 PM
"Roland Hall" wrote in message 
news:uJDtlkD%23EHA.3700@t......
:I feel I'm missing something that should be obvious.
:
: This is my XML test file.
:
: <?xml version="1.0" encoding="ISO-8859-1" ?>
: <PRODUCTS>
: <PRODUCT>
: <PRODID>BAD-Product</PRODID>
: <PRODNAME>Not Valid</PRODNAME>
: <PRODDESC>Bad Product</PRODDESC>
: <PRODPRICE>0.00</PRODPRICE>
: <PRODWEIGHT>0</PRODWEIGHT>
: <PRODQTY>1</PRODQTY>
: <SHIPPER>1</SHIPPER>
: </PRODUCT>
: <PRODUCT>
: <PRODID>GOODProduct</PRODID>
: <PRODNAME>Valid</PRODNAME>
: <PRODDESC>Good Product</PRODDESC>
: <PRODPRICE>0.00</PRODPRICE>
: <PRODWEIGHT>0</PRODWEIGHT>
: <PRODQTY>1</PRODQTY>
: <SHIPPER>1</SHIPPER>
: </PRODUCT>
: </PRODUCTS>
:
: This is my code:
:
: <%@ Language=VBScript %>
: <%
: Option Explicit
: Response.Buffer = True
: %>
: <!--#include virtual="/cart/header.asp"-->
: <%
:
: function search(prodid)
: ' --- Assign local variables ---
: dim objXML, xmlFile
: dim path, nodeitem, file, arrText
:
: ' --- array of Freight Rate Chart XML files ---
: file = num & ".xml"
:
: ' --- Make ActiveX connection to XML parser ---
: set objXML = CreateObject("MSXML2.DOMDocument.4.0")
:
: ' --- Disable asynchronous loading ---
: objXML.async = false
:
: ' --- load requested XML file into memory ---
: xmlFile = objXML.load(strPath & file)
:
: ' --- set XPATH into XML document for PRODID for queried product ID ---
: path = "PRODUCTS/PRODUCT[PRODID=" & prodid & "]"
:
: debug "Path", path
:
: ' --- assign value of node from XPATH to object node
: set nodeitem = objXML.selectSingleNode(path)
:
: lprt(nodeitem.text)
: arrText = split(nodeitem.text)
: lprt(arrText(0))
:
: end function
:
: dim prodid, num
: prodid = "GOODProduct"
: num = Request.Cookies("num")
: search prodid
:
: %>
:
: This is the debug line to show my XPATH:
: Path: PRODUCTS/PRODUCT[PRODID=GOODProduct]
:
: This is my error:
:
: Microsoft VBScript runtime error '800a01a8'
:
: Object required: 'nodeitem'
:
: /dev/modxml.asp, line 40
:
:
: This is line 40:
:
: lprt(nodeitem.text)
:
: This is the lprt subroutine:
:
: sub lprt(str)
:    Response.Write(str & "<br />" & vbCrLf)
: end sub
:
: It appears the 'set node' line is not being set for some reason.  I'm 
using
: almost the same exact code in another file and it works.  The only
: difference is the XML file, which changes the root/child/grandchild nodes
: names but the structure is a duplicate.
:
: I can set the XPATH to: PRODUCTS/PRODUCT/PRODID and put it in a loop with
: selectNodes and see the content.  I'm just not sure why the nodeitem 
object
: is not being set or as it appears.  The variable was node and I thought
: perhaps that was the issue but apparently not.
:
: Here is a working version where the XML portion asside from the names is a
: duplicate.  I've turned on the debug information where you can see the
: values.
:
: Put in your zipcode or any other valid zipcode and a weight of 100 or more
: and you will get a result, no object error.
: http://kiddanger.com/dev/searchxml.asp?z=77511&w=512

Fricken fracken...

Changing this:
path = "PRODUCTS/PRODUCT[PRODID=" & prodid & "]"

To this:
path = "PRODUCTS/PRODUCT[PRODID=""" & prodid & """]"

...solves the problem.  It doesn't explain why it works in the other file 
other than it was a zipcode, which is all numbers and perhaps text needs 
quotes.  If someone could verify that, it would be helpful.

Thanks for w3schools.com XPATH info for the clue, although it wasn't stated.

-- 
Roland Hall
/* This information is distributed in the hope that it will be useful, but 
without any warranty; without even the implied warranty of merchantability 
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.