Getting XML response back to client from ASP using XMTHTTP


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Getting XML response back to client from ASP using XMTHTTP

Hybrid View

  1. #1
    David Rancour Guest

    Getting XML response back to client from ASP using XMTHTTP


    Hi,

    I am working on my first cXML implementation and have a question. I have
    setup a test VB program to send a request to my ASP page. Seems like I can
    get the xml sent to the ASP, as I can return it immediately and my VB program
    has the correct response.xml. Here's the code from my VB program:

    Set oHTTP = New MSXML2.XMLHTTP30

    Set fso = CreateObject("scripting.filesystemobject")
    Set file = fso.OpenTextFile("c:\request.xml")

    'Read in xml from file
    Do While Not file.AtEndOfStream
    xmlRequest = xmlRequest & file.readline
    Loop
    file.Close
    Set file = Nothing
    Set fso = Nothing

    Set xmlDOM = New MSXML2.DOMDocument

    'Load xml into dom
    xmlDOM.loadXML xmlRequest

    oHTTP.open "POST", "http://drancour/cxml/punchoutrequest.asp", False
    oHTTP.setRequestHeader "Content-Type", "text/xml"
    oHTTP.send xmlDOM.xml

    Now, when on the serverside ASP page, I have to receive this xml, grab a
    couple of nodes (username and password fields). Then evaluate those and return
    cXML indicating whether or not the login credentials are valid. However,
    if login is successful I seem to be only able to evaluate the oHTTP object's
    responseBody or responseText to get the xml from my web page. I would like
    to populate the responseXML property from the page so that it can be loaded
    into a dom on the client side once it is received. Here is the ASP code:

    set xmlDOM = server.createobject("msxml2.domdocument")

    xmlDOM.async = false
    xmlDOM.load(request)

    'Evaluate the login info....

    'Assume login is OK, this would be xml to be returned to client
    xmlReturn = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _
    "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    "<cXML payloadID=""456778199@cxml.workchairs.com"" xml:lang=""enUS"" timestamp=""19990312T18:39:0908:00""
    version=""1.1.009"">" & _
    "<Response>" & _
    "<Status code=""200"" text=""OK"" />" & _
    "<PunchOutSetupResponse>" & _
    "<StartPage>" & _
    "<URL>http://premier.workchairs.com/store?23423SDFSDF23</URL>" & _
    "</StartPage>" & _
    "</PunchOutSetupResponse>" & _
    "</Response>" & _
    "</cXML>"

    xmldom.loadxml xmlReturn
    Response.ContentType = "text/xml"
    response.binarywrite xmldom.xml
    response.end

    Again, this only results in being able to grab the responseText property
    of the XMLHTTP object on the client side. What do I do in the ASP to get
    the xml to be available to the client in the responseXML property of the
    XMLHTTP object??

    Thanks in advance!!

    David Rancour
    Web Developer

  2. #2
    Russell Jones Guest

    Re: Getting XML response back to client from ASP using XMTHTTP

    David:

    All you need to do is to change the reponse type to "text/xml". In my
    experience, you don't need to use the BinaryWrite method to return the XML
    (although that works). Because the DOMDocument.xml property is a string, the
    Response.Write method works just fine.

    Russell Jones
    Sr. Web Development Editor,
    DevX.com


    "David Rancour" <drancour@columbus.rr.com> wrote in message
    news:3aed9d89$1@news.devx.com...
    >
    > Hi,
    >
    > I am working on my first cXML implementation and have a question. I have
    > setup a test VB program to send a request to my ASP page. Seems like I can
    > get the xml sent to the ASP, as I can return it immediately and my VB

    program
    > has the correct response.xml. Here's the code from my VB program:
    >
    > Set oHTTP = New MSXML2.XMLHTTP30
    >
    > Set fso = CreateObject("scripting.filesystemobject")
    > Set file = fso.OpenTextFile("c:\request.xml")
    >
    > 'Read in xml from file
    > Do While Not file.AtEndOfStream
    > xmlRequest = xmlRequest & file.readline
    > Loop
    > file.Close
    > Set file = Nothing
    > Set fso = Nothing
    >
    > Set xmlDOM = New MSXML2.DOMDocument
    >
    > 'Load xml into dom
    > xmlDOM.loadXML xmlRequest
    >
    > oHTTP.open "POST", "http://drancour/cxml/punchoutrequest.asp", False
    > oHTTP.setRequestHeader "Content-Type", "text/xml"
    > oHTTP.send xmlDOM.xml
    >
    > Now, when on the serverside ASP page, I have to receive this xml, grab a
    > couple of nodes (username and password fields). Then evaluate those and

    return
    > cXML indicating whether or not the login credentials are valid. However,
    > if login is successful I seem to be only able to evaluate the oHTTP

    object's
    > responseBody or responseText to get the xml from my web page. I would like
    > to populate the responseXML property from the page so that it can be

    loaded
    > into a dom on the client side once it is received. Here is the ASP code:
    >
    > set xmlDOM = server.createobject("msxml2.domdocument")
    >
    > xmlDOM.async = false
    > xmlDOM.load(request)
    >
    > 'Evaluate the login info....
    >
    > 'Assume login is OK, this would be xml to be returned to client
    > xmlReturn = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _
    > "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    > "<cXML payloadID=""456778199@cxml.workchairs.com"" xml:lang=""enUS""

    timestamp=""19990312T18:39:0908:00""
    > version=""1.1.009"">" & _
    > "<Response>" & _
    > "<Status code=""200"" text=""OK"" />" & _
    > "<PunchOutSetupResponse>" & _
    > "<StartPage>" & _
    > "<URL>http://premier.workchairs.com/store?23423SDFSDF23</URL>" & _
    > "</StartPage>" & _
    > "</PunchOutSetupResponse>" & _
    > "</Response>" & _
    > "</cXML>"
    >
    > xmldom.loadxml xmlReturn
    > Response.ContentType = "text/xml"
    > response.binarywrite xmldom.xml
    > response.end
    >
    > Again, this only results in being able to grab the responseText property
    > of the XMLHTTP object on the client side. What do I do in the ASP to get
    > the xml to be available to the client in the responseXML property of the
    > XMLHTTP object??
    >
    > Thanks in advance!!
    >
    > David Rancour
    > Web Developer




  3. #3
    David Rancour Guest

    Re: Getting XML response back to client from ASP using XMTHTTP


    Thanks Russell,

    But I am already setting the response type to text/xml in the intial post.
    Also, how else can I return the XML without using BinaryWrite method? Do
    I just use response.write(xmldoc)??

    Thanks again!

    "Russell Jones" <arj1@northstate.net> wrote:
    >David:
    >
    >All you need to do is to change the reponse type to "text/xml". In my
    >experience, you don't need to use the BinaryWrite method to return the XML
    >(although that works). Because the DOMDocument.xml property is a string,

    the
    >Response.Write method works just fine.
    >
    >Russell Jones
    >Sr. Web Development Editor,
    >DevX.com
    >
    >
    >"David Rancour" <drancour@columbus.rr.com> wrote in message
    >news:3aed9d89$1@news.devx.com...
    >>
    >> Hi,
    >>
    >> I am working on my first cXML implementation and have a question. I have
    >> setup a test VB program to send a request to my ASP page. Seems like I

    can
    >> get the xml sent to the ASP, as I can return it immediately and my VB

    >program
    >> has the correct response.xml. Here's the code from my VB program:
    >>
    >> Set oHTTP = New MSXML2.XMLHTTP30
    >>
    >> Set fso = CreateObject("scripting.filesystemobject")
    >> Set file = fso.OpenTextFile("c:\request.xml")
    >>
    >> 'Read in xml from file
    >> Do While Not file.AtEndOfStream
    >> xmlRequest = xmlRequest & file.readline
    >> Loop
    >> file.Close
    >> Set file = Nothing
    >> Set fso = Nothing
    >>
    >> Set xmlDOM = New MSXML2.DOMDocument
    >>
    >> 'Load xml into dom
    >> xmlDOM.loadXML xmlRequest
    >>
    >> oHTTP.open "POST", "http://drancour/cxml/punchoutrequest.asp", False
    >> oHTTP.setRequestHeader "Content-Type", "text/xml"
    >> oHTTP.send xmlDOM.xml
    >>
    >> Now, when on the serverside ASP page, I have to receive this xml, grab

    a
    >> couple of nodes (username and password fields). Then evaluate those and

    >return
    >> cXML indicating whether or not the login credentials are valid. However,
    >> if login is successful I seem to be only able to evaluate the oHTTP

    >object's
    >> responseBody or responseText to get the xml from my web page. I would

    like
    >> to populate the responseXML property from the page so that it can be

    >loaded
    >> into a dom on the client side once it is received. Here is the ASP code:
    >>
    >> set xmlDOM = server.createobject("msxml2.domdocument")
    >>
    >> xmlDOM.async = false
    >> xmlDOM.load(request)
    >>
    >> 'Evaluate the login info....
    >>
    >> 'Assume login is OK, this would be xml to be returned to client
    >> xmlReturn = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _
    >> "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    >> "<cXML payloadID=""456778199@cxml.workchairs.com"" xml:lang=""enUS""

    >timestamp=""19990312T18:39:0908:00""
    >> version=""1.1.009"">" & _
    >> "<Response>" & _
    >> "<Status code=""200"" text=""OK"" />" & _
    >> "<PunchOutSetupResponse>" & _
    >> "<StartPage>" & _
    >> "<URL>http://premier.workchairs.com/store?23423SDFSDF23</URL>" & _
    >> "</StartPage>" & _
    >> "</PunchOutSetupResponse>" & _
    >> "</Response>" & _
    >> "</cXML>"
    >>
    >> xmldom.loadxml xmlReturn
    >> Response.ContentType = "text/xml"
    >> response.binarywrite xmldom.xml
    >> response.end
    >>
    >> Again, this only results in being able to grab the responseText property
    >> of the XMLHTTP object on the client side. What do I do in the ASP to get
    >> the xml to be available to the client in the responseXML property of the
    >> XMLHTTP object??
    >>
    >> Thanks in advance!!
    >>
    >> David Rancour
    >> Web Developer

    >
    >



  4. #4
    Russell Jones Guest

    Re: Getting XML response back to client from ASP using XMTHTTP

    > But I am already setting the response type to text/xml in the intial post.
    Sorry, so you are.

    When I eliminate this line:
    "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    your code works for me. That line is not valid. If I replace it with a valid
    DOCTYPE tag, it works just fine.

    > Also, how else can I return the XML without using BinaryWrite method? Do
    > I just use response.write(xmldoc)??

    To answer your question, just use Response.Write xmlDoc.xml.

    In your client code, check for load errors:
    (the variable xhttp in the following code is an XMLHTTPRequest object).
    if xhttp.ResponseXML.parseerror.reason <> "" then
    ' show the error
    msgbox "Error loading XML" & vbcrlf & _
    "Reason: " & xhttp.ResponseXML.parseerror.reason & vbcrlf & _
    "Line: " & xhttp.ResponseXML.parseerror.line & vbcrlf & _
    "Position: " & xhttp.ResponseXML.parseerror.linepos
    else set xml = xhttp.ResponseXML
    ' no error
    msgbox xml.xml
    end if


    "David Rancour" <drancour@columbus.rr.com> wrote in message
    news:3aedac8b@news.devx.com...
    >
    > Thanks Russell,
    >
    > But I am already setting the response type to text/xml in the intial post.
    > Also, how else can I return the XML without using BinaryWrite method? Do
    > I just use response.write(xmldoc)??
    >
    > Thanks again!
    >
    > "Russell Jones" <arj1@northstate.net> wrote:
    > >David:
    > >
    > >All you need to do is to change the reponse type to "text/xml". In my
    > >experience, you don't need to use the BinaryWrite method to return the

    XML
    > >(although that works). Because the DOMDocument.xml property is a string,

    > the
    > >Response.Write method works just fine.
    > >
    > >Russell Jones
    > >Sr. Web Development Editor,
    > >DevX.com
    > >
    > >
    > >"David Rancour" <drancour@columbus.rr.com> wrote in message
    > >news:3aed9d89$1@news.devx.com...
    > >>
    > >> Hi,
    > >>
    > >> I am working on my first cXML implementation and have a question. I

    have
    > >> setup a test VB program to send a request to my ASP page. Seems like I

    > can
    > >> get the xml sent to the ASP, as I can return it immediately and my VB

    > >program
    > >> has the correct response.xml. Here's the code from my VB program:
    > >>
    > >> Set oHTTP = New MSXML2.XMLHTTP30
    > >>
    > >> Set fso = CreateObject("scripting.filesystemobject")
    > >> Set file = fso.OpenTextFile("c:\request.xml")
    > >>
    > >> 'Read in xml from file
    > >> Do While Not file.AtEndOfStream
    > >> xmlRequest = xmlRequest & file.readline
    > >> Loop
    > >> file.Close
    > >> Set file = Nothing
    > >> Set fso = Nothing
    > >>
    > >> Set xmlDOM = New MSXML2.DOMDocument
    > >>
    > >> 'Load xml into dom
    > >> xmlDOM.loadXML xmlRequest
    > >>
    > >> oHTTP.open "POST", "http://drancour/cxml/punchoutrequest.asp", False
    > >> oHTTP.setRequestHeader "Content-Type", "text/xml"
    > >> oHTTP.send xmlDOM.xml
    > >>
    > >> Now, when on the serverside ASP page, I have to receive this xml, grab

    > a
    > >> couple of nodes (username and password fields). Then evaluate those and

    > >return
    > >> cXML indicating whether or not the login credentials are valid.

    However,
    > >> if login is successful I seem to be only able to evaluate the oHTTP

    > >object's
    > >> responseBody or responseText to get the xml from my web page. I would

    > like
    > >> to populate the responseXML property from the page so that it can be

    > >loaded
    > >> into a dom on the client side once it is received. Here is the ASP

    code:
    > >>
    > >> set xmlDOM = server.createobject("msxml2.domdocument")
    > >>
    > >> xmlDOM.async = false
    > >> xmlDOM.load(request)
    > >>
    > >> 'Evaluate the login info....
    > >>
    > >> 'Assume login is OK, this would be xml to be returned to client
    > >> xmlReturn = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _
    > >> "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    > >> "<cXML payloadID=""456778199@cxml.workchairs.com"" xml:lang=""enUS""

    > >timestamp=""19990312T18:39:0908:00""
    > >> version=""1.1.009"">" & _
    > >> "<Response>" & _
    > >> "<Status code=""200"" text=""OK"" />" & _
    > >> "<PunchOutSetupResponse>" & _
    > >> "<StartPage>" & _
    > >> "<URL>http://premier.workchairs.com/store?23423SDFSDF23</URL>" & _
    > >> "</StartPage>" & _
    > >> "</PunchOutSetupResponse>" & _
    > >> "</Response>" & _
    > >> "</cXML>"
    > >>
    > >> xmldom.loadxml xmlReturn
    > >> Response.ContentType = "text/xml"
    > >> response.binarywrite xmldom.xml
    > >> response.end
    > >>
    > >> Again, this only results in being able to grab the responseText

    property
    > >> of the XMLHTTP object on the client side. What do I do in the ASP to

    get
    > >> the xml to be available to the client in the responseXML property of

    the
    > >> XMLHTTP object??
    > >>
    > >> Thanks in advance!!
    > >>
    > >> David Rancour
    > >> Web Developer

    > >
    > >

    >




  5. #5
    David Rancour Guest

    Re: Getting XML response back to client from ASP using XMTHTTP


    Thanks alot! This is a big help.

    "Russell Jones" <arj1@northstate.net> wrote:
    >> But I am already setting the response type to text/xml in the intial post.

    >Sorry, so you are.
    >
    >When I eliminate this line:
    > "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    >your code works for me. That line is not valid. If I replace it with a valid
    >DOCTYPE tag, it works just fine.
    >
    >> Also, how else can I return the XML without using BinaryWrite method?

    Do
    >> I just use response.write(xmldoc)??

    >To answer your question, just use Response.Write xmlDoc.xml.
    >
    >In your client code, check for load errors:
    >(the variable xhttp in the following code is an XMLHTTPRequest object).
    >if xhttp.ResponseXML.parseerror.reason <> "" then
    > ' show the error
    > msgbox "Error loading XML" & vbcrlf & _
    > "Reason: " & xhttp.ResponseXML.parseerror.reason & vbcrlf & _
    > "Line: " & xhttp.ResponseXML.parseerror.line & vbcrlf & _
    > "Position: " & xhttp.ResponseXML.parseerror.linepos
    >else set xml = xhttp.ResponseXML
    > ' no error
    > msgbox xml.xml
    >end if
    >
    >
    >"David Rancour" <drancour@columbus.rr.com> wrote in message
    >news:3aedac8b@news.devx.com...
    >>
    >> Thanks Russell,
    >>
    >> But I am already setting the response type to text/xml in the intial post.
    >> Also, how else can I return the XML without using BinaryWrite method?

    Do
    >> I just use response.write(xmldoc)??
    >>
    >> Thanks again!
    >>
    >> "Russell Jones" <arj1@northstate.net> wrote:
    >> >David:
    >> >
    >> >All you need to do is to change the reponse type to "text/xml". In my
    >> >experience, you don't need to use the BinaryWrite method to return the

    >XML
    >> >(although that works). Because the DOMDocument.xml property is a string,

    >> the
    >> >Response.Write method works just fine.
    >> >
    >> >Russell Jones
    >> >Sr. Web Development Editor,
    >> >DevX.com
    >> >
    >> >
    >> >"David Rancour" <drancour@columbus.rr.com> wrote in message
    >> >news:3aed9d89$1@news.devx.com...
    >> >>
    >> >> Hi,
    >> >>
    >> >> I am working on my first cXML implementation and have a question. I

    >have
    >> >> setup a test VB program to send a request to my ASP page. Seems like

    I
    >> can
    >> >> get the xml sent to the ASP, as I can return it immediately and my

    VB
    >> >program
    >> >> has the correct response.xml. Here's the code from my VB program:
    >> >>
    >> >> Set oHTTP = New MSXML2.XMLHTTP30
    >> >>
    >> >> Set fso = CreateObject("scripting.filesystemobject")
    >> >> Set file = fso.OpenTextFile("c:\request.xml")
    >> >>
    >> >> 'Read in xml from file
    >> >> Do While Not file.AtEndOfStream
    >> >> xmlRequest = xmlRequest & file.readline
    >> >> Loop
    >> >> file.Close
    >> >> Set file = Nothing
    >> >> Set fso = Nothing
    >> >>
    >> >> Set xmlDOM = New MSXML2.DOMDocument
    >> >>
    >> >> 'Load xml into dom
    >> >> xmlDOM.loadXML xmlRequest
    >> >>
    >> >> oHTTP.open "POST", "http://drancour/cxml/punchoutrequest.asp", False
    >> >> oHTTP.setRequestHeader "Content-Type", "text/xml"
    >> >> oHTTP.send xmlDOM.xml
    >> >>
    >> >> Now, when on the serverside ASP page, I have to receive this xml, grab

    >> a
    >> >> couple of nodes (username and password fields). Then evaluate those

    and
    >> >return
    >> >> cXML indicating whether or not the login credentials are valid.

    >However,
    >> >> if login is successful I seem to be only able to evaluate the oHTTP
    >> >object's
    >> >> responseBody or responseText to get the xml from my web page. I would

    >> like
    >> >> to populate the responseXML property from the page so that it can be
    >> >loaded
    >> >> into a dom on the client side once it is received. Here is the ASP

    >code:
    >> >>
    >> >> set xmlDOM = server.createobject("msxml2.domdocument")
    >> >>
    >> >> xmlDOM.async = false
    >> >> xmlDOM.load(request)
    >> >>
    >> >> 'Evaluate the login info....
    >> >>
    >> >> 'Assume login is OK, this would be xml to be returned to client
    >> >> xmlReturn = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _
    >> >> "<!DOCTYPE cXML (View Source for full doctype...)>" & _
    >> >> "<cXML payloadID=""456778199@cxml.workchairs.com"" xml:lang=""enUS""
    >> >timestamp=""19990312T18:39:0908:00""
    >> >> version=""1.1.009"">" & _
    >> >> "<Response>" & _
    >> >> "<Status code=""200"" text=""OK"" />" & _
    >> >> "<PunchOutSetupResponse>" & _
    >> >> "<StartPage>" & _
    >> >> "<URL>http://premier.workchairs.com/store?23423SDFSDF23</URL>" & _
    >> >> "</StartPage>" & _
    >> >> "</PunchOutSetupResponse>" & _
    >> >> "</Response>" & _
    >> >> "</cXML>"
    >> >>
    >> >> xmldom.loadxml xmlReturn
    >> >> Response.ContentType = "text/xml"
    >> >> response.binarywrite xmldom.xml
    >> >> response.end
    >> >>
    >> >> Again, this only results in being able to grab the responseText

    >property
    >> >> of the XMLHTTP object on the client side. What do I do in the ASP to

    >get
    >> >> the xml to be available to the client in the responseXML property of

    >the
    >> >> XMLHTTP object??
    >> >>
    >> >> Thanks in advance!!
    >> >>
    >> >> David Rancour
    >> >> Web Developer
    >> >
    >> >

    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center