|
Subject:
|
Saving XML HELP!!!
|
|
Posted By:
|
busher
|
Post Date:
|
11/5/2004 3:00:50 PM
|
I am posting form information to a site that returns an xml page with data that our company needs. I am very new to the XML world, and I don't understand how to automatically save the returned xml page locally.
Since the returned page requires form data, I cannot do the following:
xml.Open "GET", "http://www.somesite.com", False
which is common on all of the examples I have seen on the net. I would like our intranet users to be able to click on a page; it sends the form data, saves the returned page, and then runs a parser to consume the data.
Can someone please help me?
|
|
Reply By:
|
Ajay Swamy
|
Reply Date:
|
11/23/2004 11:27:59 AM
|
This is what you do:
Use your appropriate MSXML Object, then use store the returned XML (from get or post) into a variable. Use the FileSystem Object to write the XML locally (hence cached XML). You can they reference the file into your transform code for XSL., You can also directly parse the stored XML in the variable. Warning: its a little slow!!
Sample code:
Dim file_out1, objXMLHttp1, response_xml1 Set objXmlHttp1 = Server.CreateObject("Msxml2.ServerXMLHTTP") objXmlHttp1.open "GET", YOUR_url & "YOUR PARAMETERS", False objXmlHttp1.send response_xml1 = objXmlHttp1.responseXML
NOW transform with XSL:
Set objXML = Server.CreateObject("Microsoft.XMLDOM") objXML.async = False objXML.Load(response_xml1)
Set objXSL = Server.CreateObject("Microsoft.XMLDOM") objXSL.async = false objXSL.load("YOUR location of XSL file - absolute URL") xmlResponseDoc = objXML.transformNode(objXSL)
and thats it.
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
11/23/2004 11:34:44 AM
|
This function retrieves any sort of file from the web:
function saveRemoteFile(From, To)
{
var oXmlHttp = new ActiveXObject("Msxml2.XmlHttp.4.0"); //Change to version 3 if necessary
oXmlHttp.open("GET", From, false);
oXmlHttp.send();
if (oXmlHttp.status == 200)
{
var oStream = new ActiveXObject("Adodb.Stream");
oStream.type = 1; //Binary
oStream.open();
oStream.write(oXmlHttp.responseBody);
oStream.saveToFile(To, 1 && 2);
oStream.close();
}
else
{
throw new Error(oXmlHttp.statusText); //Needs improving
}
}
saveRemoteFile("http://www.google.com", "C:\\myFolder\\myGooglePage.htm");
If you know the data is going to be XML then once you have opened and sent you can just do:
//create msxml2.xmlhttp.4.0, open and send
oXmlHttp.responseXML.save(<path to save to>);
--
Joe (Microsoft MVP - XML)
|