?
Solved

XMLHTTP - screen scrape

Posted on 2003-10-27
2
Medium Priority
?
966 Views
Last Modified: 2007-12-19
Hi Experts,

I have the following xml file called "contacts.xml"

<xmp>
<?xml version="1.0"?>
<contacts>
     <contact>
          <field id="firstName" taborder="1">
               <field_value>richard</field_value>
          </field>
          <field id="lastName" taborder="2">
               <field_value>jones</field_value>
          </field>
          <field id="address1" taborder="3">
               <field_value>16 some street</field_value>
          </field>
          <field id="address2" taborder="4">
               <field_value>london</field_value>
          </field>
          <field id="phone" taborder="5">
               <field_value>123456</field_value>
          </field>
          <field id="email" taborder="6">
               <field_value>someemail</field_value>
          </field>
     </contact>
</contacts>
</xmp>


And I am loading it into a page called "scrape1.asp" which uses the "microsoft.XMLHTTP" object to retieve the XML data as follows:


<%@ Language = VBScript %>
<%
Response.Buffer = True
Dim objXMLHTTP, xml

Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

xml.Open "GET", "http://myurl/xmlTests/contact.xml", False

xml.Send

'Display the HTML as text...
'Response.Write "<xmp>"
'Response.Write xml.responseText
'Response.Write "</xmp>"

'Or, render the HTML...
Response.Write xml.responseText
 
Set xml = Nothing

%>


The xml page is being rendered to the screen within scrape1.asp as expected. I have a couple of questions...


1.

How do I grab information from within the object based on the xml field name and stuff the results into a set of variables?


2.

I would also like to use this object to retrieve pure HTML pages. I would then like to grab information from the HTML pages using the regular expression object. Can you please give me an example of how to do this? An example of what I am tring to do would be:

HMTL = <td>price = £29.30</td>

VALUE IN VARIABLE = <% price %> (where price would = "29.30")




Thanks for you help...




PJORDANNA

0
Comment
Question by:pjordanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
deighc earned 1000 total points
ID: 9658082
>> 1. How do I grab information from within the object based on the xml field name and stuff the results into a set of variables?

You mean you want to loop thru the XML and read out the attributes and/or node text??? Something like this:

<%
' Add this code after xml.send and before set xml = nothing
' Dim these variable names: xmlNodeList, xmlNode

' Select a list of XML nodes
set xmlNodeList = xml.documentElement.selectNodes("/contacts/contact/field")
' Loop thru the node list
for each xmlNode in xmlNodeList
  ' Now you have access to the attributes collection of the <field> node
  Response.write "ID = " & xmlNode.attributes.getNamedItem("id").text
  Response.write "taborder = " & xmlNode.attributes.getNamedItem("id").text
  ' If you want access the text value of <field_value> node....
  Response.write "Value of field_value = " & xmlNode.childNodes(0).text
next
set xmlNodeList = nothing
%>

As for your second question, well, that's an entirely seperate problem and you really ought to post it as a different question. And my reg exp skills are crap.....  ;-)
0
 

Author Comment

by:pjordanna
ID: 9677339
deighc,

Cheers for that...works a treat.



pjordanna
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

764 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