sending xml through a form field, not in body

sending xml through a form field, not in body

am 11.11.2007 00:22:00 von betty

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="firstDoc doc"
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.a sp",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmltext="xml=firstDoc doc"

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:


so my xmtext will become
xmltext="xml= orderID='200704251114527189'>"

or xmltext="xml=" & "first
try
"

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

Re: sending xml through a form field, not in body

am 11.11.2007 18:27:21 von Anthony Jones

"c676228" wrote in message
news:06146BA5-E8F0-40D0-ABA8-A894E7016568@microsoft.com...
> 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="firstDoc doc"
> 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.a sp",false
> xmlhttp.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
> xmltext="xml=firstDoc doc"
>
> 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:
>
>

> so my xmtext will become
> xmltext="xml= > orderID='200704251114527189'>"
>
> or xmltext="xml=" & "first
> try
"
>
> 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("firstDoc doc")


--
Anthony Jones - MVP ASP/ASP.NET

Re: sending xml through a form field, not in body

am 11.11.2007 19:43:00 von betty

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


"Anthony Jones" wrote:

> "c676228" wrote in message
> news:06146BA5-E8F0-40D0-ABA8-A894E7016568@microsoft.com...
> > 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="firstDoc doc"
> > 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.a sp",false
> > xmlhttp.setRequestHeader "Content-Type",
> "application/x-www-form-urlencoded"
> > xmltext="xml=firstDoc doc"
> >
> > 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:
> >
> >

> > so my xmtext will become
> > xmltext="xml= > > orderID='200704251114527189'>"
> >
> > or xmltext="xml=" & "first
> > try
"
> >
> > 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("firstDoc doc")
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>
>