This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > October 2004 > can't read the returned xml document
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
can't read the returned xml document
|
|
| Nancy Drew 2004-10-18, 7:15 pm |
| hi all
i've written a simple asp page that posts a XML doc to another asp page. the
second asp page reads the nodes and then should write back to the calling
page some of the node data (the pages actually do a little more than that,
but i'll try to keep this as simple as possible). here's the posting
instructions from page #1:
set oXmlHttp = server.CreateObject("Microsoft.XMLHTTP")
oXmlHttp.open "POST",
"http://wip/secure/wip/distributech/WebSite/receive_post_fax.asp", False '//
open http connection to the server //
oXmlHttp.setRequestHeader "Content-type", "text/xml"
oXmlHttp.send oXMLDocument
'// process the server response//
iResponseStatus = oXMLHttp.status
sResponseMsg = oXMLHttp.responseText
if iResponseStatus = 200 then '// success //
sResponseXML = oXMLHttp.responseXML.xml
set oXMLDoc = Server.CreateObject("MSxml2.domdocument.4.0")
oXMLDoc.load(sResponseXML)
response.write "Does the returned XML doc have child nodes? " &
oXMLDoc.hasChildNodes & ". If yes, we're okay to proceed with parsing the
data..."
else
response.Write "<h1>Post Error</h1><p>" & sResponseMsg & "</p>"
end if
the code from page #2 that sends the response XML look like so:
'// create the response XML document to send back to the originating server
//
oXMLDoc.loadXML "<faxTransactionRecord />"
set oRoot = oXMLDoc.documentElement
set oElement = oXMLDoc.createElement("transactionNumber")
oElement.text = sTransNum
oRoot.appendChild oElement
set oElement = oXMLDoc.createElement("status")
oElement.text = "Fax sent"
oRoot.appendChild oElement
Response.ContentType="text/xml"
oXMLDoc.save(Response)
if i view source on the web browser, i can see the XML data, but i can't
seem to read it in as an XML doc. any ideas what i'm doing wrong?
| |
| Jonathan Chong 2004-10-19, 4:14 am |
| What I can see here is the problem of using method "load". Load method is
for loading an XML document from specified location. Where loadXML is for
loading XML document using the supplied string. In your case you should use
loadXML. And do error checking with this:
IF oXMLDoc.loadXML(sResponseXML) = FALSE THEN
'''do error handling here'''
END IF
"Nancy Drew" <genpub5@hotmail.com> wrote in message
news:xfidnSFCnvYAZO7cRVn-2w@rogers.com...
> hi all
>
> i've written a simple asp page that posts a XML doc to another asp page.
the
> second asp page reads the nodes and then should write back to the calling
> page some of the node data (the pages actually do a little more than that,
> but i'll try to keep this as simple as possible). here's the posting
> instructions from page #1:
>
> set oXmlHttp = server.CreateObject("Microsoft.XMLHTTP")
> oXmlHttp.open "POST",
> "http://wip/secure/wip/distributech/WebSite/receive_post_fax.asp", False
'//
> open http connection to the server //
> oXmlHttp.setRequestHeader "Content-type", "text/xml"
> oXmlHttp.send oXMLDocument
>
> '// process the server response//
> iResponseStatus = oXMLHttp.status
> sResponseMsg = oXMLHttp.responseText
> if iResponseStatus = 200 then '// success //
> sResponseXML = oXMLHttp.responseXML.xml
> set oXMLDoc = Server.CreateObject("MSxml2.domdocument.4.0")
> oXMLDoc.load(sResponseXML)
> response.write "Does the returned XML doc have child nodes? " &
> oXMLDoc.hasChildNodes & ". If yes, we're okay to proceed with parsing the
> data..."
> else
> response.Write "<h1>Post Error</h1><p>" & sResponseMsg & "</p>"
> end if
>
>
> the code from page #2 that sends the response XML look like so:
>
> '// create the response XML document to send back to the originating
server
> //
> oXMLDoc.loadXML "<faxTransactionRecord />"
> set oRoot = oXMLDoc.documentElement
>
> set oElement = oXMLDoc.createElement("transactionNumber")
> oElement.text = sTransNum
> oRoot.appendChild oElement
>
> set oElement = oXMLDoc.createElement("status")
> oElement.text = "Fax sent"
> oRoot.appendChild oElement
>
> Response.ContentType="text/xml"
> oXMLDoc.save(Response)
>
> if i view source on the web browser, i can see the XML data, but i can't
> seem to read it in as an XML doc. any ideas what i'm doing wrong?
>
>
| |
| Joe Fawcett 2004-10-19, 12:14 pm |
| "Nancy Drew" <genpub5@hotmail.com> wrote in message
news:xfidnSFCnvYAZO7cRVn-2w@rogers.com...
> hi all
>
> i've written a simple asp page that posts a XML doc to another asp page.
the
> second asp page reads the nodes and then should write back to the calling
> page some of the node data (the pages actually do a little more than that,
> but i'll try to keep this as simple as possible). here's the posting
> instructions from page #1:
>
> set oXmlHttp = server.CreateObject("Microsoft.XMLHTTP")
> oXmlHttp.open "POST",
> "http://wip/secure/wip/distributech/WebSite/receive_post_fax.asp", False
'//
> open http connection to the server //
> oXmlHttp.setRequestHeader "Content-type", "text/xml"
> oXmlHttp.send oXMLDocument
>
> '// process the server response//
> iResponseStatus = oXMLHttp.status
> sResponseMsg = oXMLHttp.responseText
> if iResponseStatus = 200 then '// success //
> sResponseXML = oXMLHttp.responseXML.xml
> set oXMLDoc = Server.CreateObject("MSxml2.domdocument.4.0")
> oXMLDoc.load(sResponseXML)
> response.write "Does the returned XML doc have child nodes? " &
> oXMLDoc.hasChildNodes & ". If yes, we're okay to proceed with parsing the
> data..."
> else
> response.Write "<h1>Post Error</h1><p>" & sResponseMsg & "</p>"
> end if
>
>
> the code from page #2 that sends the response XML look like so:
>
> '// create the response XML document to send back to the originating
server
> //
> oXMLDoc.loadXML "<faxTransactionRecord />"
> set oRoot = oXMLDoc.documentElement
>
> set oElement = oXMLDoc.createElement("transactionNumber")
> oElement.text = sTransNum
> oRoot.appendChild oElement
>
> set oElement = oXMLDoc.createElement("status")
> oElement.text = "Fax sent"
> oRoot.appendChild oElement
>
> Response.ContentType="text/xml"
> oXMLDoc.save(Response)
>
> if i view source on the web browser, i can see the XML data, but i can't
> seem to read it in as an XML doc. any ideas what i'm doing wrong?
>
>
I think this is right:
set oXMLDoc = Server.CreateObject("MSxml2.domdocument.4.0")
oXMLDoc.load(oXMLHttp.responseXML)
The only thing is the response might not be XML or it might be that the
wrong content type is being returned by the server.
The load method loads from a filename or an object implementing IStream,
e.g. ADO.Stream, Request object in ASP, or another DomDocument.
--
Joe (MVP - xml)
| |
| Nancy Drew 2004-10-19, 12:14 pm |
| thansk to jonathan and joe. the problem was related to the way i was trying
to load the XML doc. both of your suggestions worked.
--
---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"
Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://mail.spaminspector.com
"Nancy Drew" <genpub5@hotmail.com> wrote in message
news:xfidnSFCnvYAZO7cRVn-2w@rogers.com...
> hi all
>
> i've written a simple asp page that posts a XML doc to another asp page.
the
> second asp page reads the nodes and then should write back to the calling
> page some of the node data (the pages actually do a little more than that,
> but i'll try to keep this as simple as possible). here's the posting
> instructions from page #1:
>
> set oXmlHttp = server.CreateObject("Microsoft.XMLHTTP")
> oXmlHttp.open "POST",
> "http://wip/secure/wip/distributech/WebSite/receive_post_fax.asp", False
'//
> open http connection to the server //
> oXmlHttp.setRequestHeader "Content-type", "text/xml"
> oXmlHttp.send oXMLDocument
>
> '// process the server response//
> iResponseStatus = oXMLHttp.status
> sResponseMsg = oXMLHttp.responseText
> if iResponseStatus = 200 then '// success //
> sResponseXML = oXMLHttp.responseXML.xml
> set oXMLDoc = Server.CreateObject("MSxml2.domdocument.4.0")
> oXMLDoc.load(sResponseXML)
> response.write "Does the returned XML doc have child nodes? " &
> oXMLDoc.hasChildNodes & ". If yes, we're okay to proceed with parsing the
> data..."
> else
> response.Write "<h1>Post Error</h1><p>" & sResponseMsg & "</p>"
> end if
>
>
> the code from page #2 that sends the response XML look like so:
>
> '// create the response XML document to send back to the originating
server
> //
> oXMLDoc.loadXML "<faxTransactionRecord />"
> set oRoot = oXMLDoc.documentElement
>
> set oElement = oXMLDoc.createElement("transactionNumber")
> oElement.text = sTransNum
> oRoot.appendChild oElement
>
> set oElement = oXMLDoc.createElement("status")
> oElement.text = "Fax sent"
> oRoot.appendChild oElement
>
> Response.ContentType="text/xml"
> oXMLDoc.save(Response)
>
> if i view source on the web browser, i can see the XML data, but i can't
> seem to read it in as an XML doc. any ideas what i'm doing wrong?
>
>
| |
| David C 2004-10-19, 7:15 pm |
| Nancy,
I have a similar need, however I need to send a request to a web server and
it returns XML information. Would my code be similar to yours, and would I
need to use "GET" instead of "POST"? Thanks.
David
"Nancy Drew" <genpub5@hotmail.com> wrote in message
news:xfidnSFCnvYAZO7cRVn-2w@rogers.com...
> hi all
>
> i've written a simple asp page that posts a XML doc to another asp page.
the
> second asp page reads the nodes and then should write back to the calling
> page some of the node data (the pages actually do a little more than that,
> but i'll try to keep this as simple as possible). here's the posting
> instructions from page #1:
>
> set oXmlHttp = server.CreateObject("Microsoft.XMLHTTP")
> oXmlHttp.open "POST",
> "http://wip/secure/wip/distributech/WebSite/receive_post_fax.asp", False
'//
> open http connection to the server //
> oXmlHttp.setRequestHeader "Content-type", "text/xml"
> oXmlHttp.send oXMLDocument
>
> '// process the server response//
> iResponseStatus = oXMLHttp.status
> sResponseMsg = oXMLHttp.responseText
> if iResponseStatus = 200 then '// success //
> sResponseXML = oXMLHttp.responseXML.xml
> set oXMLDoc = Server.CreateObject("MSxml2.domdocument.4.0")
> oXMLDoc.load(sResponseXML)
> response.write "Does the returned XML doc have child nodes? " &
> oXMLDoc.hasChildNodes & ". If yes, we're okay to proceed with parsing the
> data..."
> else
> response.Write "<h1>Post Error</h1><p>" & sResponseMsg & "</p>"
> end if
>
>
> the code from page #2 that sends the response XML look like so:
>
> '// create the response XML document to send back to the originating
server
> //
> oXMLDoc.loadXML "<faxTransactionRecord />"
> set oRoot = oXMLDoc.documentElement
>
> set oElement = oXMLDoc.createElement("transactionNumber")
> oElement.text = sTransNum
> oRoot.appendChild oElement
>
> set oElement = oXMLDoc.createElement("status")
> oElement.text = "Fax sent"
> oRoot.appendChild oElement
>
> Response.ContentType="text/xml"
> oXMLDoc.save(Response)
>
> if i view source on the web browser, i can see the XML data, but i can't
> seem to read it in as an XML doc. any ideas what i'm doing wrong?
>
>
| |
| Neil Smith [MVP Digital Media] 2004-10-19, 7:15 pm |
| Generally you'd send GET rather than POST, it really depends on what
the web server is expecting to receive :
GET requests are normally used for requests which don't change
anything on the server. POST is usually used when too much information
is needed to be passed to the server for a get request (over 4kb), or
when you expect to change something like a database by making the
request.
In most scripting languages (PHP, ASP, etc) the server expects to look
in a particular collection of variables for the data, so if you send a
GET request to a script expecting data as a POST body, then it won't
respond (good) or crash / have unexpected behaviour (bad). It depends
how the script handling the request was written.
In most cases, something returning an XML dataset is going to expect a
GET request, so try this first.
Cheers - Neil
On Tue, 19 Oct 2004 14:32:38 -0500, "David C"
<dlchase@lifetimeinc.com> wrote:
>Nancy,
>
>I have a similar need, however I need to send a request to a web server and
>it returns XML information. Would my code be similar to yours, and would I
>need to use "GET" instead of "POST"? Thanks.
>
>David
>
>"Nancy Drew" <genpub5@hotmail.com> wrote in message
>news:xfidnSFCnvYAZO7cRVn-2w@rogers.com...
>the
>'//
>server
>
| |
|
| It worked BOTH ways...why???
David
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
| |
| Jonathan Chong 2004-10-19, 11:14 pm |
| Like what Neil explained. It depends on how the target Web server receives
incoming data.
For example (in ASP), if the target Web server receives data with:
1. Request.Form("param") - This works for POST.
2. Request.QueryString("param") - This works for GET
Hope this explains.
"David" <daman@biteme.com> wrote in message
news:eeeQgXitEHA.1048@tk2msftngp13.phx.gbl...
> It worked BOTH ways...why???
>
> David
>
>
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!
| |
| Neil Smith [MVP Digital Media] 2004-10-20, 12:15 pm |
| Well in some scripting languages, notable PHP, it was possible at some
times to access the GET and POST variables as global variables. So for
example in PHP you would look for
$result=$_GET["my_get_variable"]; // or
$result=$_POST["my_get_variable"];
In some setups with PHP, there was a setting called 'register_globals'
and it was on. What this did was pass any submitted form (or web
service) variables directlty into the namespace of the script
processor. So you'd actually have access to a variable called
$my_get_variable
and it's value would be whatever was sent to the web service. You can
imagine, this is a security risk, where you don't know where your
values came from, and could lead to spoofing with badly written
scripts. In all modern versions of PHP this setting is off by default.
However, your web service can still be set to respond to either
method, simply by doing
<php
if ($_GET && isset($_GET["my_get_variable"])) {
$my_get_variable=trim($_GET["my_web_variable"]);
print("Data was sent by GET method");
}
if ($_POST && isset($_POST["my_get_variable"])) {
$my_get_variable=trim($_POST["my_web_variable"]);
print("Data was sent by POST method");
}
?>
Exactly equivalent ways of doing this exist in ASP (using the
request.querystring and request.form collections) and in pretty much
any other web language I care to think of.
On Tue, 19 Oct 2004 14:52:04 -0700, David <daman@biteme.com> wrote:
>It worked BOTH ways...why???
>
>David
>
>
>
>*** Sent via Developersdex http://www.codecomments.com ***
>Don't just participate in USENET...get rewarded for it!
| |
| David 2004-10-20, 12:15 pm |
| Thank you all. You have been extremely helpful.
David
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|