Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2004, 03:05 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Urgent Help!

I need a code example of how to save an XML page that is returned to my browser via a form post. Can anyone please help???
 
Old November 11th, 2004, 05:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Firstly we probably need a bit more info. What sort of values are sent from the form? If they are just ones like name etc. then the msxml2.xmlhttp.4.0 class can send these values and collect the response. There are lots of examples in these formus or get the docs from Microsoft or view online.

Secondly please give your posts sensible titles.

If you need more help let me know. It would be esay if the form were on the Web so I could try it myself.



--

Joe (Microsoft MVP - XML)
 
Old November 19th, 2004, 12:19 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, there are 6 values that I send via a form to a sight:

<form method="post" action="http://agquote.dtn.com/quotes/ProcessQuoteTagAllQuotes_XML.cfm">
<input type="hidden" name="username" value="XXXXXX">
<input type="hidden" name="password" value="XXXXXX">
<input type="hidden" name="format" value="XML">
<input type="hidden" name="service" value="QTETAB">
<input type="hidden" name="symbol" value="LC">
<input type="submit" name="submit" value="Submit">
</form>

Once I send this form, it returns an XML page that I need to dump the data from to our sql database. Email me an I will give you the username and password if you really need them.



 
Old November 22nd, 2004, 07:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Try this script, copy and save a .js file.
Code:
function getHttpReq()
{
  try
  {
    return new ActiveXObject("Msxml2.XmlHttp.4.0");
  }
  catch(e)
  {
    try
    {
      return new ActiveXObject("Msxml2.XmlHttp.3.0");
    }
    catch(e)
    {
      return null;
    }
  }
}

function getResponse(Url, Method, Data)
{
  var oReq = getHttpReq();
  if (!oReq)
  {
    WScript.echo("You need to install Microsoft XML core services version 4.");
    return null;
  }
  oReq.open(Method, Url, false);
  if (Data)
  {
    oReq.send(Data);
  }
  else
  {
    oReq.send();
  }
  if (oReq.status != 200)
  {
    WScript.echo("Error retrieving data: " + oReq.statusText);
    return null;
  }
  WScript.echo(oReq.getAllResponseHeaders());
  return oReq;
}

function encodeData(Data)
{
  if (encodeURIComponent)
  {
    return encodeURIComponent(Data);
  }
  return escape(Data);
}

function main()
{
  var sUrl = "http://agquote.dtn.com/quotes/ProcessQuoteTagAllQuotes_XML.cfm";
  var sData = "username=" + encodeData("xxxxxx");
  sData + "&password=" + encodeData("xxxxxx");
  sData + "&format=" + encodeData("XML");
  sData + "&service=" + encodeData("QTETAB");
  sData + "&symbol=" + encodeData("LC");
  sData + "&submit=" + encodeData("Submit");
  var oResponse = getResponse(sUrl , "POST", sData);
  if (oResponse)
  {
    if (oResponse.responseXML && oResponse.responseXML.xml)
    {
      WScript.echo(oResponse.responseXML.xml);
    }
    else
    {
      WScript.echo(oResponse.responseText);
    }
    oResponse = null;
  }
  WScript.quit(); 
}

main();
--

Joe (Microsoft MVP - XML)
 
Old November 23rd, 2004, 11:21 AM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, I wanted to take a quick break to give a special thanks to Joe and all the other "reponders" who take the time to help us out. These forums gives all programmers incredible tools in which to perform our jobs and help take care of our families, at least that is true in my case. With out some people who take the time out of their lives to answer seemingly stupid questions from people they don't even know, some of us would be in big trouble.

Thanks Guys and Girls!!!

 
Old November 23rd, 2004, 11:29 AM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get the following error:

Microsoft JScript runtime error: "WScript" undefined on -

WScript.echo("Error retrieving data: " + oReq.statusText);

 
Old November 23rd, 2004, 12:19 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How are you running the code, it wont work in a browser, only as a standalone js file?
To run in browser (with sufficiently low security settings) replace WScript.echo with alert and remove the WScript.quit line.



--

Joe (Microsoft MVP - XML)
 
Old November 23rd, 2004, 01:05 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get "Error Retrieving data: Internal Server Error". How would I use this js file outside of a browser. I don't guess I have ever done that before. What I did was:

<script type="text/javascript" src="xmlpost.js"></script>

and I put it inside the body tags.

What exactly does this js file do? Does it create an XML page or what?

 
Old November 23rd, 2004, 01:21 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Just open notepad, paste in the code and save as "getXml.js" with the quotes!
(remember to add the corrct name and password)
Then double click on the file. It should just show the returned xml.

--

Joe (Microsoft MVP - XML)
 
Old November 23rd, 2004, 01:27 PM
Authorized User
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, I did, and I get the same error.






Similar Threads
Thread Thread Starter Forum Replies Last Post
urgent deb_kareng ASP.NET 2.0 Professional 1 August 13th, 2007 07:29 AM
it's urgent deb_kareng ASP.NET 2.0 Professional 3 August 7th, 2007 07:40 AM
urgent help yash_coolbuddy_forindia BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 May 7th, 2007 08:40 AM
urgent???????????? nsr35 Beginning VB 6 1 October 3rd, 2005 10:57 AM
urgent ??????????????? nsr35 Pro VB Databases 0 October 3rd, 2005 04:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.