Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

objXMLDOM.Load From URL?

I have the following ASP code which works great. What I want to do though is load the xml from a url over http.  I know I can use a dll to grab the url stream then save this to a localdisk file and do it that way.  Can you bypass teh save to disk bit though and load xml directly into the parser?

Thanks

Dave

  Dim objXMLParser
  Dim rootNode
 
  Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")
 
  objXMLDOM.async = False
  objXMLDOM.Load (Server.MapPath("/Xml Stuff/Friends.xml"))
 
  Set rootNode = objXMLDOM.documentElement
 
  If rootNode.hasChildNodes() Then
    For Each friend in rootNode.childNodes
      For Each item in friend.childNodes
        Response.Write item.nodeName & ": " & item.Text & "<br/>"
      Next
      Response.Write "<hr/>"
    Next  
  End If
0
daveamour
Asked:
daveamour
  • 2
  • 2
1 Solution
 
ASPGuruCommented:
lookup XMLHTTP in you documentation

ASPGuru
0
 
daveamourAuthor Commented:
Thanks due.  Me is a bit thick though and needs things pointing out.  I managed to get something working with XMLHTTP but I had top save it to disk.

This is what I have below, can I do this without saving to disk though?

  Dim objXML
  Dim objFSO
  Dim objFile
 
  Set objXML = CreateObject("Microsoft.XMLHTTP")
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
 
  strURL = "http://localhost/xml%20stuff/Friends.xml"
 
  objXML.Open "GET", strURL, False
  objXML.Send    
 
  xmlGet = objXML.responseText
 
  Set objFile = objFSO.OpenTextFile (Server.MapPath("/xml stuff/downloads/") & "\" & "friends.xml", 2, True)
  objFile.Write xmlGet
 
  Set objFile = Nothing
  Set objFSO = Nothing
 
  Dim objXMLParser
  Dim rootNode
 
  Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")
 
  objXMLDOM.async = False
  objXMLDOM.Load (Server.MapPath("/Xml Stuff/Friends.xml"))
 
  Set rootNode = objXMLDOM.documentElement
 
  If rootNode.hasChildNodes() Then
    For Each friend in rootNode.childNodes
      For Each item in friend.childNodes
        Response.Write item.nodeName & ": " & item.Text & "<br/>"
      Next
      Response.Write "<hr/>"
    Next  
  End If  

Thanks

Dave
0
 
ASPGuruCommented:
yes you can do without saving...
instead of this:
xmlGet = objXML.responseText
you can do this:
Set xmlDoc = objXML.responseXML

xmlDoc is a Microsoft.XMLDOM object...

another suggestion:

the Microsoft.XMLDOM and Microsoft.XMLHTTP objects are actually old versions of the xml objects.

newer versions of the objects are downloadable from microsoft and comes with every IE...

the new names are:
Msxml2.DOMDocument
and
Msxml2.XMLHTTP
0
 
daveamourAuthor Commented:
Thanks dude!

Dave
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now