sending xml through a form field, not in body

C

c676228

Hi all,
I wrote an asp program which can receive xml string from a client program if
they send me a xml in the body. It is OK.(Anthony Jones helped me) But now,
our client suggests that they are willing to send me xml string through a
field, say xml="<document>firstDoc doc</document>"
So I have to write a testing program to make sure that our server can take it.
Here is my client side testing program:
Set xmlDom=CreateObject("Microsoft.XMLDOM")

XMLDom.async =False
dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open
"POST","xxxx.com/select2007/xt_select2007_CompleteB2B_test.asp",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmltext="xml=<enrollment>firstDoc doc</enrollment>"

xmlhttp.send xmltext
...

Response.ContentType = "text/xml"
Response.Write xmlhttp.responsexml.xml
Set xmlhttp = nothing

so I have to use the following code on the server side:
Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.LoadXML Request("xml")
....
it seems Ok,(but one thing is very strange: the space between the text of
the node disappears when the xml string displayed in the broswer, it becomes
firstDocdoc somehow) even worse when my xml string becomes more complicated,
it's messed up.
say if I have some attribute in the node:
<enrollment productName="Select" orderID="200704251114527189" >
</enrollment>
so my xmtext will become
xmltext="xml=<enrollment productName='Select'
orderID='200704251114527189'></enrollment>"

or xmltext="xml=" & "<enrollment name=""" & "Betty Sun" & """>first
try</enrollment>"

In IE, it will give me error message:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.

XML document must have a top level element. Error processing resource
'http://localhost/1109selectserverhttp.asp'.

Or in FireFox, it will have:
XML Parsing Error: no element found
Location: http://localhost/1109selectserverhttp.asp
Line Number 1, Column 1:

Can you tell me how to deal with it in this case?
Betty
 
A

Anthony Jones

c676228 said:
Hi all,
I wrote an asp program which can receive xml string from a client program if
they send me a xml in the body. It is OK.(Anthony Jones helped me) But now,
our client suggests that they are willing to send me xml string through a
field, say xml="<document>firstDoc doc</document>"
So I have to write a testing program to make sure that our server can take it.
Here is my client side testing program:
Set xmlDom=CreateObject("Microsoft.XMLDOM")

XMLDom.async =False
dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open
"POST","xxxx.com/select2007/xt_select2007_CompleteB2B_test.asp",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmltext="xml=<enrollment>firstDoc doc</enrollment>"

xmlhttp.send xmltext
...

Response.ContentType = "text/xml"
Response.Write xmlhttp.responsexml.xml
Set xmlhttp = nothing

so I have to use the following code on the server side:
Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.LoadXML Request("xml")
...
it seems Ok,(but one thing is very strange: the space between the text of
the node disappears when the xml string displayed in the broswer, it becomes
firstDocdoc somehow) even worse when my xml string becomes more complicated,
it's messed up.
say if I have some attribute in the node:
<enrollment productName="Select" orderID="200704251114527189" >
</enrollment>
so my xmtext will become
xmltext="xml=<enrollment productName='Select'
orderID='200704251114527189'></enrollment>"

or xmltext="xml=" & "<enrollment name=""" & "Betty Sun" & """>first
try</enrollment>"

In IE, it will give me error message:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.

XML document must have a top level element. Error processing resource
'http://localhost/1109selectserverhttp.asp'.

Or in FireFox, it will have:
XML Parsing Error: no element found
Location: http://localhost/1109selectserverhttp.asp
Line Number 1, Column 1:

Can you tell me how to deal with it in this case?

Hi Betty,

When a value is posted as field value of a HTML form the value is encoded as
if it were part of a URL. That's why the a POSTed forms content type is
called "application/x-form-urlencoded", note the last word in the type.

Hence in your test program try using Server.URLEncode like this:-

xmltext= "xml=" & Server.URLEncode("<enrollment>firstDoc doc</enrollment>")
 
C

c676228

All right. thank you so much and you saved more hours for me.
Got it and it runs perfectly. Great great help.
Sincrely
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top