sparky74
asked on
ASP startpoint when parsing xml
Hi
I am trying to get the results from an amazon xml feed using asp/ xml the following code works but only if the start point is valid. the startpoint is looking for <OurPrice> but if the product is not in stock the <OurPrice> attribute is not returned through the xml so my script crashes, what I need it to do is if the startpoint <OurPrice> is not returned set the value of strPrice to '0.00', the variable strPrice is then being used in an update statement to set the price in my database. I would like to try and get an answer in classic asp please,
here is the code
I'm using, I have taken out my developer token so the link to amazon will crash in this example
Dim objXML
Set objXML = Server.CreateObject("MSXML 2.ServerXM LHTTP.6.0" )
strURL ="http://xml-eu.amazon.com/onca/xml3?t=webservices-20&dev-t=&AsinSearch=B0009yjb1g&type=lite&page=1&locale=uk&f=xml"
objXML.Open "GET" , strURL , False ,"",""
objXML.Send
If objXML.Status = 200 then
strOpen = objXML.ResponseText
vStartAt1 = 1
do while vStartAt1 <> -1
startPoint= InStr(vStartAt1, strOpen, "<OurPrice>") 'Look for start string, start looking from cursor location.
'========================
If startPoint = 0 or IsNull(startPoint) then
exit do
end if
'========================
if startPoint <> -1 then
endPoint = InStr(startPoint, strOpen, "</OurPrice>")
if endPoint <> -1 then
strPrice = Mid(strOpen, startPoint, endPoint-startPoint)
strPrice = Replace(strPrice, "'", """")
strPrice = Replace(strPrice, "<OurPrice>", "")
strPrice = Replace(strPrice, "£", "")
Set db1 = server.CreateObject("ADODB .Connectio n")
db1.open MM_luxurygifts_STRING
strSQL1 = "UPDATE dbo.thomas SET pricecheckstatus = '2', pricecheck = (" & strPrice & ") FROM thomas WHERE id=151"
set rs1 = db1.execute(strSQL1)
set rs1 = nothing
db1.close
set db1 = nothing
Else
end if
vStartAt1 = endPoint
end if
loop
End if
Set objXML = Nothing
I am trying to get the results from an amazon xml feed using asp/ xml the following code works but only if the start point is valid. the startpoint is looking for <OurPrice> but if the product is not in stock the <OurPrice> attribute is not returned through the xml so my script crashes, what I need it to do is if the startpoint <OurPrice> is not returned set the value of strPrice to '0.00', the variable strPrice is then being used in an update statement to set the price in my database. I would like to try and get an answer in classic asp please,
here is the code
I'm using, I have taken out my developer token so the link to amazon will crash in this example
Dim objXML
Set objXML = Server.CreateObject("MSXML
strURL ="http://xml-eu.amazon.com/onca/xml3?t=webservices-20&dev-t=&AsinSearch=B0009yjb1g&type=lite&page=1&locale=uk&f=xml"
objXML.Open "GET" , strURL , False ,"",""
objXML.Send
If objXML.Status = 200 then
strOpen = objXML.ResponseText
vStartAt1 = 1
do while vStartAt1 <> -1
startPoint= InStr(vStartAt1, strOpen, "<OurPrice>") 'Look for start string, start looking from cursor location.
'========================
If startPoint = 0 or IsNull(startPoint) then
exit do
end if
'========================
if startPoint <> -1 then
endPoint = InStr(startPoint, strOpen, "</OurPrice>")
if endPoint <> -1 then
strPrice = Mid(strOpen, startPoint, endPoint-startPoint)
strPrice = Replace(strPrice, "'", """")
strPrice = Replace(strPrice, "<OurPrice>", "")
strPrice = Replace(strPrice, "£", "")
Set db1 = server.CreateObject("ADODB
db1.open MM_luxurygifts_STRING
strSQL1 = "UPDATE dbo.thomas SET pricecheckstatus = '2', pricecheck = (" & strPrice & ") FROM thomas WHERE id=151"
set rs1 = db1.execute(strSQL1)
set rs1 = nothing
db1.close
set db1 = nothing
Else
end if
vStartAt1 = endPoint
end if
loop
End if
Set objXML = Nothing
Just out of curiousity, why in the world are you using string functions when you can use MSXML to parse the Xml Document?
ASKER
Thanks for the reply, I have never used MSXML to parse an XML Document before, in fact I didn't even know about it :(
I used the above script to scrape some info from one of our asp pages before and thought it would work in a similar way, which is does, but I have the problem when the <price> element is'nt returned.
I will search now for some info on MSXML, any examples of how I could achieve the above would be grateful
thanks
I used the above script to scrape some info from one of our asp pages before and thought it would work in a similar way, which is does, but I have the problem when the <price> element is'nt returned.
I will search now for some info on MSXML, any examples of how I could achieve the above would be grateful
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the comments, I found some info and got it sorted using the MSXML DOM to parse out the nodes