Parsing an xml http request... with asp

Discussion in 'OT Technology' started by 2000GT, Apr 11, 2007.

  1. 2000GT

    2000GT Active Member

    Joined:
    Jan 21, 2001
    Messages:
    5,773
    Likes Received:
    8
    Location:
    Vancouver
    I am trying to incorperate a url string's response into an asp page. Basically, I request a url such as:

    http://enterprise.w3data.com/directaccess?ver=2.0&type=p&data=n&p=4253921111

    It returns a page like this:

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <RESULTS>
    - <INFO>
    <VERSION>2.0</VERSION>
    <STATUS>OK</STATUS>
    <SEARCH_ID>40111310633470914033</SEARCH_ID>
    <SEARCH_TYPE>Reverse_Phone</SEARCH_TYPE>
    <COUNT>1</COUNT>
    </INFO>
    - <LISTINGS>
    - <LISTING>
    - <NAME>
    <FIRST>Charleen</FIRST>
    <FIRST_2>Roger</FIRST_2>
    <FIRST_3>Nancy</FIRST_3>
    <LAST>Vail</LAST>
    </NAME>
    - <ADDRESS>
    <NUM>15607</NUM>
    <STREET>258th Pl SE</STREET>
    <CITY>Issaquah</CITY>
    <STATE>WA</STATE>
    <ZIP>98027</ZIP>
    <ZIP4>8257</ZIP4>
    <COUNTRY>United States</COUNTRY>
    <DPC>075</DPC>
    <CR>R002</CR>
    </ADDRESS>
    <PHONE>4253921111</PHONE>
    <CARRIER>Qwest Corporation</CARRIER>
    <TYPE>Geographic</TYPE>
    - <GEO_EXTRA>
    <LATITUDE>47.462896</LATITUDE>
    <LONGITUDE>-121.99634</LONGITUDE>
    <FIPS>53033</FIPS>
    <MSA>7600</MSA>
    <Z4_TYPE>S</Z4_TYPE>
    <GEO_PREC>0</GEO_PREC>
    </GEO_EXTRA>
    <LISTING_ID>1</LISTING_ID>
    </LISTING>
    </LISTINGS>
    </RESULTS>

    I want to take parts of the data of that page and populate it into an asp page of mine.

    I don't even know where to start, as w3schools tutorial doesnt seem to give me what I want, and googling the information is taking forever.

    I have never programmed xml at all, so a little point in the right direction would be great!
    Thank You.
     
  2. gnp

    gnp New Member

    Joined:
    Mar 11, 2007
    Messages:
    280
    Likes Received:
    0
    you can apply an xsl transform to the incoming xml and iframe it in your asp page. kinda kludgey

    or use msxml6 to parse the xml

    What you are doing is essentially calling a web service from your page. Asp.net would be a better choice for that.
     
  3. 2000GT

    2000GT Active Member

    Joined:
    Jan 21, 2001
    Messages:
    5,773
    Likes Received:
    8
    Location:
    Vancouver
    Thanks, I am creating a web app that will allow a user to do a reverse lookup on a phonenumber that is on screen.

    Basically, the user will have a screen with a phone number and address fields. Only the phonenumber will be populated. Once the user needs the address info, he will click a link that will load the remaining address fields with information.

    The link he is clicking will be a url to a phone number reverse lookup site that will return the information in xml.
     
  4. 2000GT

    2000GT Active Member

    Joined:
    Jan 21, 2001
    Messages:
    5,773
    Likes Received:
    8
    Location:
    Vancouver
    I have tried to run this code:

    <html>
    <head>
    <script type="text/javascript">
    var xmlhttp

    function loadXMLDoc(url)
    {
    xmlhttp=null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
    xmlhttp=new XMLHttpRequest()
    }
    // code for IE
    else if (window.ActiveXObject)
    {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp!=null)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,false)
    xmlhttp.send(null)
    }
    else
    {
    alert("Your browser does not support XMLHTTP.")
    }
    }


    function state_Change()
    {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
    {
    // if "OK"
    if (xmlhttp.status==200)
    {
    alert("XML data OK")
    document.getElementById('A1').innerHTML=xmlhttp.status
    document.getElementById('A2').innerHTML=xmlhttp.statusText
    document.getElementById('A3').innerHTML=xmlhttp.responseText
    }
    else
    {
    alert("Problem retrieving XML data:" + xmlhttp.statusText)
    }
    }
    }

    </script>
    </head>

    <body onload="loadXMLDoc('http://enterprise.w3data.com/directaccess?ver=2.0&type=p&data=n&p=4253921111')">
    <h2>Using the HttpRequest Object</h2>

    <p><b>status:</b>
    <span id="A1"></span>
    </p>

    <p><b>status text:</b>
    <span id="A2"></span>
    </p>

    <p><b>response:</b>
    <br><span id="A3"></span>
    </p>

    </body>
    </html>





    But all I get is access denied js error!
     
  5. gnp

    gnp New Member

    Joined:
    Mar 11, 2007
    Messages:
    280
    Likes Received:
    0
    are you using ie or ff? i know ff doesn't allow a xmlHttpRequest to a different domain by default, you can change this though.
     
  6. gnp

    gnp New Member

    Joined:
    Mar 11, 2007
    Messages:
    280
    Likes Received:
    0
  7. 2000GT

    2000GT Active Member

    Joined:
    Jan 21, 2001
    Messages:
    5,773
    Likes Received:
    8
    Location:
    Vancouver

Share This Page