|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
sending xml through a form field, not in body
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 Show quote
"c676228" <betty@newsgroup.nospam> wrote in message "application/x-www-form-urlencoded"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="<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", Show quote > xmltext="xml=<enrollment>firstDoc doc</enrollment>" Hi Betty,> > 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? 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>") -- Anthony Jones - MVP ASP/ASP.NET All right. thank you so much and you saved more hours for me.
Got it and it runs perfectly. Great great help. Sincrely -- Betty Show quote "Anthony Jones" wrote: > "c676228" <betty@newsgroup.nospam> 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="<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>") > > > -- > Anthony Jones - MVP ASP/ASP.NET > > > |
|||||||||||||||||||||||