sending xml through a form field, not in body

Discussion in 'ASP General' started by c676228, Nov 10, 2007.

  1. c676228

    c676228 Guest

    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
     
    c676228, Nov 10, 2007
    #1
    1. Advertising

  2. "c676228" <> wrote in message
    news:...
    > 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
     
    Anthony Jones, Nov 11, 2007
    #2
    1. Advertising

  3. c676228

    c676228 Guest

    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:...
    > > 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
    >
    >
    >
     
    c676228, Nov 11, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NotGiven
    Replies:
    3
    Views:
    389
    Michael D. Kersey
    May 13, 2004
  2. GavMc
    Replies:
    4
    Views:
    385
    Evertjan.
    Sep 22, 2005
  3. London Boy
    Replies:
    2
    Views:
    359
    Keith Bowes
    Jan 12, 2004
  4. Sound
    Replies:
    2
    Views:
    503
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    502
Loading...

Share This Page