How to Extract URL from XML page using ASP code
How to Extract URL from XML page using ASP code
am 18.08.2007 06:56:36 von Billy
Can anyone guide me to a resource for learning how to extract a URL
from an XML page using ASP 3.0 code?
This link below is an Amazon web services link that produces an XML
page. The resulting XML page has another URL embedded within it that I
need to extract and use to redirect the site to it's final URL
destination.
http://webservices.amazon.com/onca/xml?Service=AWSECommerceS ervice&AWSAccessKeyIdESSKEY&Operation=CartCreate&Item.1.A SIN°00E73MO0&Item.1.Quantity=1&Item.2.ASIN°0005T3E4&Item .2.Quantity=1&Item.3.ASIN°00BOLJ64&Item.3.Quantity=1
Re: How to Extract URL from XML page using ASP code
am 18.08.2007 13:10:27 von reb01501
Billy wrote:
> Can anyone guide me to a resource for learning how to extract a URL
> from an XML page using ASP 3.0 code?
>
> This link below is an Amazon web services link that produces an XML
> page. The resulting XML page has another URL embedded within it that I
> need to extract and use to redirect the site to it's final URL
> destination.
>
> http://webservices.amazon.com/onca/xml?Service=AWSECommerceS ervice&AWSAccessKeyIdESSKEY&Operation=CartCreate&Item.1.A SIN°00E73MO0&Item.1.Quantity=1&Item.2.ASIN°0005T3E4&Item .2.Quantity=1&Item.3.ASIN°00BOLJ64&Item.3.Quantity=1
set urlnode = xmldoc.selectSingle Node("/CartCreateResponse")
url=urlnode.getAttribute("xmlns")
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Re: How to Extract URL from XML page using ASP code
am 19.08.2007 03:40:08 von Billy
On Aug 18, 7:10 am, "Bob Barrows [MVP]"
wrote:
> Billy wrote:
> > Can anyone guide me to a resource for learning how to extract a URL
> > from an XML page using ASP 3.0 code?
>
> > This link below is an Amazon web services link that produces an XML
> > page. The resulting XML page has another URL embedded within it that I
> > need to extract and use to redirect the site to it's final URL
> > destination.
>
> >http://webservices.amazon.com/onca/xml?Service=AWSECommerce Service&AW...
>
> set urlnode = xmldoc.selectSingle Node("/CartCreateResponse")
> url=urlnode.getAttribute("xmlns")
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
I dont understand what this is. Where does my URL go? Where do you
specify the data you ant to extract in the URL?
Re: How to Extract URL from XML page using ASP code
am 19.08.2007 06:21:39 von Billy
On Aug 18, 7:10 am, "Bob Barrows [MVP]"
wrote:
> Billy wrote:
> > Can anyone guide me to a resource for learning how to extract a URL
> > from an XML page using ASP 3.0 code?
>
> > This link below is an Amazon web services link that produces an XML
> > page. The resulting XML page has another URL embedded within it that I
> > need to extract and use to redirect the site to it's final URL
> > destination.
>
> >http://webservices.amazon.com/onca/xml?Service=AWSECommerce Service&AW...
>
> set urlnode = xmldoc.selectSingle Node("/CartCreateResponse")
> url=urlnode.getAttribute("xmlns")
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
OK, I read up on the XML DOM and I coded this. However, I get the
message
Microsoft VBScript runtime error '800a01a8'
Object required
/amazon_cart.asp, line 17
Line #17 is the url = urlnode.getAttribute("xmlns") coded line as
shown below......
Amazon Cart
<%
Dim objXML
Set objXML = Server.CreateObject("Msxml2.DOMDocument.3.0")
objXML.async = False
objXML.Load("http://webservices.amazon.com/onca/xml?
Service=AWSECommerceService&AWSAccessKeyIdCESSID&Operatio n=CartCreate&Item.
1.ASIN°00E73MO0" &_
"&Item.1.Quantity=1&Item.2.ASIN°0005T3E4&Item.
2.Quantity=1&Item.3.ASIN°00BOLJ64&Item.3.Quantity=1")
Set urlnode = objXML.selectSingleNode("/CartCreateResponse")
url = urlnode.getAttribute("xmlns")
Response.Write url
Set objXML = Nothing
%>
Is this code compatible with the 3.0 ver of DOM? Could it be something
needed on the hosted server side? I use DiscountASP.net which just
about covers all technologies.....
Re: How to Extract URL from XML page using ASP code
am 19.08.2007 10:59:27 von Anthony Jones
"Billy" wrote in message
news:1187497299.291728.123240@k79g2000hse.googlegroups.com.. .
> On Aug 18, 7:10 am, "Bob Barrows [MVP]"
> wrote:
> > Billy wrote:
> > > Can anyone guide me to a resource for learning how to extract a URL
> > > from an XML page using ASP 3.0 code?
> >
> > > This link below is an Amazon web services link that produces an XML
> > > page. The resulting XML page has another URL embedded within it that I
> > > need to extract and use to redirect the site to it's final URL
> > > destination.
> >
> >
>http://webservices.amazon.com/onca/xml?Service=AWSECommerce Service&AW...
> >
> > set urlnode = xmldoc.selectSingle Node("/CartCreateResponse")
> > url=urlnode.getAttribute("xmlns")
> >
> > --
> > Microsoft MVP - ASP/ASP.NET
> > Please reply to the newsgroup. This email account is my spam trap so I
> > don't check it very often. If you must reply off-line, then remove the
> > "NO SPAM"
>
> OK, I read up on the XML DOM and I coded this. However, I get the
> message
>
> Microsoft VBScript runtime error '800a01a8'
> Object required
> /amazon_cart.asp, line 17
>
>
> Line #17 is the url = urlnode.getAttribute("xmlns") coded line as
> shown below......
>
>
>
>
>
> Amazon Cart
>
>
>
>
> <%
> Dim objXML
> Set objXML = Server.CreateObject("Msxml2.DOMDocument.3.0")
> objXML.async = False
> objXML.Load("http://webservices.amazon.com/onca/xml?
>
Service=AWSECommerceService&AWSAccessKeyIdCESSID&Operatio n=CartCreate&Ite
m.
> 1.ASIN°00E73MO0" &_
> "&Item.1.Quantity=1&Item.2.ASIN°0005T3E4&Item.
> 2.Quantity=1&Item.3.ASIN°00BOLJ64&Item.3.Quantity=1")
>
> Set urlnode = objXML.selectSingleNode("/CartCreateResponse")
> url = urlnode.getAttribute("xmlns")
> Response.Write url
>
> Set objXML = Nothing
> %>
>
>
>
> Is this code compatible with the 3.0 ver of DOM? Could it be something
> needed on the hosted server side? I use DiscountASP.net which just
> about covers all technologies.....
>
The error you are getting is due to the urlnode being Nothing. This is in
turn is due to the XML not containing a CartCreateResponse root node.
Which is probably because the Load failed. Load returns true if it has
successfully loaded the content.
After calling objXML.load you should check objXML.parseError.errorCode is 0.
If not then there was a problem loading or parsing the document.
objXML.parseError.reason will specify what went wrong.
Note before calling load you should use this line of code:-
objXML.setProperty "ServerHTTPRequest", True
Try using:-
Response.Write objXML.parseError.reason
just to see if things are OK.
Then try:-
Response.Content-Type = "text/xml"
Response.CharSet = "UTF-8"
objXML.save Response
to see the actual XML received.
Once you're happy you getting the expected XML you can change your code to
start actually using it.
--
Anthony Jones - MVP ASP/ASP.NET
Re: How to Extract URL from XML page using ASP code
am 19.08.2007 18:31:25 von Billy
On Aug 19, 4:59 am, "Anthony Jones" wrote:
> "Billy" wrote in message
>
> news:1187497299.291728.123240@k79g2000hse.googlegroups.com.. .
>
>
>
> > On Aug 18, 7:10 am, "Bob Barrows [MVP]"
> > wrote:
> > > Billy wrote:
> > > > Can anyone guide me to a resource for learning how to extract a URL
> > > > from an XML page using ASP 3.0 code?
>
> > > > This link below is an Amazon web services link that produces an XML
> > > > page. The resulting XML page has another URL embedded within it tha=
t I
> > > > need to extract and use to redirect the site to it's final URL
> > > > destination.
>
> >http://webservices.amazon.com/onca/xml?Service=3DAWSECommer ceService&AW.=
..
>
> > > set urlnode =3D xmldoc.selectSingle Node("/CartCreateResponse")
> > > url=3Durlnode.getAttribute("xmlns")
>
> > > --
> > > Microsoft MVP - ASP/ASP.NET
> > > Please reply to the newsgroup. This email account is my spam trap so I
> > > don't check it very often. If you must reply off-line, then remove the
> > > "NO SPAM"
>
> > OK, I read up on the XML DOM and I coded this. However, I get the
> > message
>
> > Microsoft VBScript runtime error '800a01a8'
> > Object required
> > /amazon_cart.asp, line 17
>
> > Line #17 is the url =3D urlnode.getAttribute("xmlns") coded line as
> > shown below......
>
> >
>
> >
> > Amazon Cart
> >
>
> >
>
> > <%
> > Dim objXML
> > Set objXML =3D Server.CreateObject("Msxml2.DOMDocument.3.0")
> > objXML.async =3D False
> > objXML.Load("http://webservices.amazon.com/onca/xml?
>
> Service=3DAWSECommerceService&AWSAccessKeyId=3DACCESSID&Oper ation=3DCartC=
reate&It=ADe
> m.
>
>
>
>
>
> > 1.ASIN=3DB000E73MO0" &_
> > "&Item.1.Quantity=3D1&Item.2.ASIN=3DB00005T3E4&Item.
> > 2.Quantity=3D1&Item.3.ASIN=3DB000BOLJ64&Item.3.Quantity=3D1" )
>
> > Set urlnode =3D objXML.selectSingleNode("/CartCreateResponse")
> > url =3D urlnode.getAttribute("xmlns")
> > Response.Write url
>
> > Set objXML =3D Nothing
> > %>
>
> >
>
> > Is this code compatible with the 3.0 ver of DOM? Could it be something
> > needed on the hosted server side? I use DiscountASP.net which just
> > about covers all technologies.....
>
> The error you are getting is due to the urlnode being Nothing. This is in
> turn is due to the XML not containing a CartCreateResponse root node.
> Which is probably because the Load failed. Load returns true if it has
> successfully loaded the content.
>
> After calling objXML.load you should check objXML.parseError.errorCode is=
0.
> If not then there was a problem loading or parsing the document.
> objXML.parseError.reason will specify what went wrong.
>
> Note before calling load you should use this line of code:-
>
> objXML.setProperty "ServerHTTPRequest", True
>
> Try using:-
>
> Response.Write objXML.parseError.reason
>
> just to see if things are OK.
>
> Then try:-
>
> Response.Content-Type =3D "text/xml"
> Response.CharSet =3D "UTF-8"
> objXML.save Response
>
> to see the actual XML received.
>
> Once you're happy you getting the expected XML you can change your code to
> start actually using it.
>
> --
> Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
I used the objXML.setProperty "ServerHTTPRequest", True right before
the XML load and this worked - I recvd back the contents of the xmlns
tag in my browser. Thank you!
However, I really need to grab the PurchaseURL in tis XML (shown
below) and submit it automatically to the browser. I suspect that I
will use a Response.Redirect to submit the PurchaseURL, but I need to
understand how to get to it first.
I looked on the web for SlectSingleNode syntax and I've had a real
hard time getting good information on it for beginners. I've also read
through XML DOM in W3 Schools, but have yet to find out how the
SelectSingleNode parameters works. I suspect that I'm using the
correct function by using SelectSingleNode (If I'm wrong, please
advise).
I really just need to understand how to navigate through the nodes to
grab what I want. Any examples would be appreciated.
Here is the XML that I load:
-
AWSECommerceService/2005-10-05">
+
-
Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.0.3705; .NET CLR
11.4322)" />
1Y86JP8EYYVME4ZVD8ZG
-
0.232803106307983
-
-
True
-
-
-
B000E73MO0
1
-
B00005T3E4
1
-
B000BOLJ64
1
102-8451736
8Ii25TILTMsE7n2zl=3D
8Ii25TILTMsE7n2zln%2BoVMt5Hn0%3D
https://www.amazon.com/gp/cart/aws-merge.html?cart-
id=3D102-8451736%26associate-id=3DMt5Hn0=3D
%26SubscriptionId=3DG2%26MergeCart=3DFalse
-
9191
USD
$91.91
-
-
9191
USD
$91.91
-
U2XH7SPFEHRQLD
B000E73MO0
ATVPDKIKX0DER
A2R2RITDJNW1Q6
Amazon.com
1
Mrs. Meyer's Clean Day Counter Top Spray, Lavender, Case of 6
- 16 Ounce Bottles (96 Ounces)
Drugstore
-
2754
USD
$27.54
-
2754
USD
$27.54
-
U1QXVOR3X7NSH0
B00005T3E4
ATVPDKIKX0DER
A2R2RITDJNW1Q6
Amazon.com
1
Duracell Ultra AAA Batteries - 8-Pack
Drugstore
-
599
USD
$5.99
-
599
USD
$5.99
-
U2BTS0V2OTNF7J
B000BOLJ64
ATVPDKIKX0DER
A2R2RITDJNW1Q6
Amazon.com
1
Tide Free Powder Detergent, Case Pack, Four - 60 Load Boxes
(240 Loads)
Drugstore
-
5838
USD
$58.38
-
5838
USD
$58.38
Re: How to Extract URL from XML page using ASP code
am 19.08.2007 23:56:52 von Anthony Jones
"Billy" wrote in message
news:1187541085.227030.201890@50g2000hsm.googlegroups.com...
On Aug 19, 4:59 am, "Anthony Jones" wrote:
> "Billy" wrote in message
>
> news:1187497299.291728.123240@k79g2000hse.googlegroups.com.. .
>
>
>>>>>>>>>>>>>
I used the objXML.setProperty "ServerHTTPRequest", True right before
the XML load and this worked - I recvd back the contents of the xmlns
tag in my browser. Thank you!
However, I really need to grab the PurchaseURL in tis XML (shown
below) and submit it automatically to the browser. I suspect that I
will use a Response.Redirect to submit the PurchaseURL, but I need to
understand how to get to it first.
I looked on the web for SlectSingleNode syntax and I've had a real
hard time getting good information on it for beginners. I've also read
through XML DOM in W3 Schools, but have yet to find out how the
SelectSingleNode parameters works. I suspect that I'm using the
correct function by using SelectSingleNode (If I'm wrong, please
advise).
I really just need to understand how to navigate through the nodes to
grab what I want. Any examples would be appreciated.
Here is the XML that I load:
-
+
-
1Y86JP8EYYVME4ZVD8ZG
-
0.232803106307983
-
-
True
-
-
-
B000E73MO0
1
-
B00005T3E4
1
-
B000BOLJ64
1
102-8451736
8Ii25TILTMsE7n2zl=
8Ii25TILTMsE7n2zln%2BoVMt5Hn0%3D
https://www.amazon.com/gp/cart/aws-merge.html?cart-
id=102-8451736%26associate-id=Mt5Hn0=
%26SubscriptionId=G2%26MergeCart=False
-
9191
USD
$91.91
-
-
9191
USD
$91.91
-
U2XH7SPFEHRQLD
B000E73MO0
ATVPDKIKX0DER
A2R2RITDJNW1Q6
Amazon.com
1
Mrs. Meyer's Clean Day Counter Top Spray, Lavender, Case of 6
- 16 Ounce Bottles (96 Ounces)
Drugstore
-
2754
USD
$27.54
-
2754
USD
$27.54
-
U1QXVOR3X7NSH0
B00005T3E4
ATVPDKIKX0DER
A2R2RITDJNW1Q6
Amazon.com
1
Duracell Ultra AAA Batteries - 8-Pack
Drugstore
-
599
USD
$5.99
-
599
USD
$5.99
-
U2BTS0V2OTNF7J
B000BOLJ64
ATVPDKIKX0DER
A2R2RITDJNW1Q6
Amazon.com
1
Tide Free Powder Detergent, Case Pack, Four - 60 Load Boxes
(240 Loads)
Drugstore
-
5838
USD
$58.38
-
5838
USD
$58.38
<<<<<<<<<<<<<<<<<<
elemPurchaseURL =
objXML.selectSingleNode("/CartCreateResponse/Cart/PurchaseUR L")
If Not elemPurchaseURL is Nothing Then
Response.Redirect elemPurchaseURL.text
Else
Response.Write "Purchase URL not found"
End If
If you want to understand what selectSingleNode is doing you also need to
read w3schools XPath tutorial. However be aware that they've updated it to
reflect XPath 2.0 but MSXML only supports XPath 1.0. In fact by default
MSXML 3 use XSL pattern as a selection language. Since the query path in
this case is so simple this doesn't matter. However to use other features
of XPath you would need another setProperty call:-
objXML.setProperty "SelectionLanguage", "XPath"
or if you know your ISP has MSXML 6 installed use the .6.0 ProgIDs instead.
BTW, does anybody know why Outlook Express sometimes fails to indent quoted
text?
--
Anthony Jones - MVP ASP/ASP.NET
Re: How to Extract URL from XML page using ASP code
am 20.08.2007 02:51:38 von Billy
On Aug 19, 5:56 pm, "Anthony Jones" wrote:
> "Billy" wrote in message
>
> news:1187541085.227030.201890@50g2000hsm.googlegroups.com...
> On Aug 19, 4:59 am, "Anthony Jones" wrote:> "Billy" wrote in message
>
> >news:1187497299.291728.123240@k79g2000hse.googlegroups.com. ..
>
> I used the objXML.setProperty "ServerHTTPRequest", True right before
> the XML load and this worked - I recvd back the contents of the xmlns
> tag in my browser. Thank you!
>
> However, I really need to grab the PurchaseURL in tis XML (shown
> below) and submit it automatically to the browser. I suspect that I
> will use a Response.Redirect to submit the PurchaseURL, but I need to
> understand how to get to it first.
>
> I looked on the web for SlectSingleNode syntax and I've had a real
> hard time getting good information on it for beginners. I've also read
> through XML DOM in W3 Schools, but have yet to find out how the
> SelectSingleNode parameters works. I suspect that I'm using the
> correct function by using SelectSingleNode (If I'm wrong, please
> advise).
>
> I really just need to understand how to navigate through the nodes to
> grab what I want. Any examples would be appreciated.
>
> Here is the XML that I load:
>
>
> -
> +
> -
>
>
> 1Y86JP8EYYVME4ZVD8ZG
> -
>
>
>
>
>
>
>
>
>
>
> 0.232803106307983
>
> -
> -
> True
> -
> -
> -
> B000E73MO0
> 1
>
> -
> B00005T3E4
> 1
>
> -
> B000BOLJ64
> 1
>
>
>
>
> 102-8451736
> 8Ii25TILTMsE7n2zl=
> 8Ii25TILTMsE7n2zln%2BoVMt5Hn0%3D
> https://www.amazon.com/gp/cart/aws-merge.html?cart-
> id=102-8451736%26associate-id=Mt5Hn0=
> %26SubscriptionId=G2%26MergeCart=False
> -
> 9191
> USD
> $91.91
>
> -
> -
> 9191
> USD
> $91.91
>
> -
> U2XH7SPFEHRQLD
> B000E73MO0
> ATVPDKIKX0DER
> A2R2RITDJNW1Q6
> Amazon.com
> 1
> Mrs. Meyer's Clean Day Counter Top Spray, Lavender, Case of 6
> - 16 Ounce Bottles (96 Ounces)
> Drugstore
> -
> 2754
> USD
> $27.54
>
> -
> 2754
> USD
> $27.54
>
>
> -
> U1QXVOR3X7NSH0
> B00005T3E4
> ATVPDKIKX0DER
> A2R2RITDJNW1Q6
> Amazon.com
> 1
> Duracell Ultra AAA Batteries - 8-Pack
> Drugstore
> -
> 599
> USD
> $5.99
>
> -
> 599
> USD
> $5.99
>
>
> -
> U2BTS0V2OTNF7J
> B000BOLJ64
> ATVPDKIKX0DER
> A2R2RITDJNW1Q6
> Amazon.com
> 1
> Tide Free Powder Detergent, Case Pack, Four - 60 Load Boxes
> (240 Loads)
> Drugstore
> -
> 5838
> USD
> $58.38
>
> -
> 5838
> USD
> $58.38
>
>
>
>
>
>
> <<<<<<<<<<<<<<<<<<
>
> elemPurchaseURL =
> objXML.selectSingleNode("/CartCreateResponse/Cart/PurchaseUR L")
>
> If Not elemPurchaseURL is Nothing Then
> Response.Redirect elemPurchaseURL.text
> Else
> Response.Write "Purchase URL not found"
> End If
>
> If you want to understand what selectSingleNode is doing you also need to
> read w3schools XPath tutorial. However be aware that they've updated it to
> reflect XPath 2.0 but MSXML only supports XPath 1.0. In fact by default
> MSXML 3 use XSL pattern as a selection language. Since the query path in
> this case is so simple this doesn't matter. However to use other features
> of XPath you would need another setProperty call:-
>
> objXML.setProperty "SelectionLanguage", "XPath"
>
> or if you know your ISP has MSXML 6 installed use the .6.0 ProgIDs instead.
>
> BTW, does anybody know why Outlook Express sometimes fails to indent quoted
> text?
>
> --
> Anthony Jones - MVP ASP/ASP.NET
Anthony,
Thank you. I will try your code and recommended reading and post the
results.
For OL2003 ( I suspect similar options in OE)......
Play with these options.....
Tools/Prefences/EMail Options
See sections "On Replies and Forwards"
When Replying to a Message: Include and Indent Orginal Message Text
When Fowarding a Message: Include and Indent Orginal Message Text
Re: How to Extract URL from XML page using ASP code
am 20.08.2007 22:23:49 von Anthony Jones
"Billy" wrote in message
news:1187571098.930386.85380@d55g2000hsg.googlegroups.com...
> On Aug 19, 5:56 pm, "Anthony Jones" wrote:
> > "Billy" wrote in message
> >
> > or if you know your ISP has MSXML 6 installed use the .6.0 ProgIDs
instead.
> >
> > BTW, does anybody know why Outlook Express sometimes fails to indent
quoted
> > text?
> >
> > --
> > Anthony Jones - MVP ASP/ASP.NET
>
> Anthony,
>
> Thank you. I will try your code and recommended reading and post the
> results.
>
> For OL2003 ( I suspect similar options in OE)......
>
> Play with these options.....
>
> Tools/Prefences/EMail Options
> See sections "On Replies and Forwards"
> When Replying to a Message: Include and Indent Orginal Message Text
> When Fowarding a Message: Include and Indent Orginal Message Text
>
Yes I've got those settings already it's just that with some messages it
just fails to kick in. Wierd.
--
Anthony Jones - MVP ASP/ASP.NET