SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot manic's Avatar
    Join Date
    Dec 2001
    Location
    uk
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    polling for my own XML doc with asp

    I'm brand new to this, so a few of the things I'm asking for may not be as you would usually expect to see them... please bare with me.

    I want to post some XML to a page (done this before and confident the code I'm using is correct)

    Code:
     <%
     xmldata = "<?xml version=""1.0""?> " & vbnewline & _
     		"<root> " & vbnewline & _
     			"<to>a</to> " & vbnewline & _
     		"</root> "
     
     '-----------------------------------------------------------------------------
     ' Connect to XML gateway
     '-----------------------------------------------------------------------------
     	sURI = "http://www.mysite.com/receiveXML.asp"
     	set oHTTP = Server.createObject("MSXML2.XMLHTTP")
     	oHTTP.open "get", sURI, false
     	oHTTP.setRequestHeader "Content-Type", "text/xml"
     	oHTTP.send xmldata
     	
     '---------------------------------------------------------------------------------
     '- Load the response xml
     '---------------------------------------------------------------------------------
     	SET rdom = Server.CreateObject("microsoft.XMLDOM")
     	rdom.async = False
     	rdom.validateOnParse = False
     	rdom.resolveExternals = False
     	rdom.preserveWhiteSpace = True
     	SET CreateDOM = rdom
     
     	
     	if rDom.LoadXML(oHTTP.responseText) = true then
     		respones.wite oHTTP.responseText
     	else
     		response.write rDom.LoadXML(oHTTP.responseText)
     	end if
     %>
    the receiveXML page (this is the part I'm new to no idea if I'm right or wrong)

    Code:
     <%
     set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
     xmldoc.async=false
     xmldoc.load(request)
     
     for each x in xmldoc.documentElement.childNodes
        if x.NodeName = "to" then name=x.text
     next
     response.write(name)
     %>
    problem is nothing ever comes back... from what I've learnt so far anything in the response.write should act as a xml response but i'm getting nothing but a big fat false from the xmlLoad

    can anyone help me out?

    In the grand scheme of things I have an application wishing to send an XML doc to me, and it wants a response back before it continues processing information.
    Don't you just hate it when it works first time.

  2. #2
    SitePoint Zealot manic's Avatar
    Join Date
    Dec 2001
    Location
    uk
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone done anything like this before at all?

    I've been on this for a week now but other than the example code I have so far I'm drawing blanks, it's as if no-one's gone into this. Which can't be true because I deal with apps which handle my XML information all the time.

    From what I've read it should be as easy as just writing

    xmldoc.load(request)

    but unfortunatly this isn't the case, at the moment being able to receive any form of response back is more important than actually receiving the data.

    If anyone can walk me through the processes, that alone would be a big help because after the initial XML post I'm not entirely sure what happens. Does it jump to the receiveXML page? or does it keep on the XML sending page and wait for a response? is there anything I have to do inbetween?
    Don't you just hate it when it works first time.

  3. #3
    SitePoint Zealot manic's Avatar
    Join Date
    Dec 2001
    Location
    uk
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update: [edit got it sorted!!]

    Had a little success with this... amazingly most of it was due to responseText and responseXML methods being used incorrectly (already kicked myself repeatedly)

    /*What I'm left with now has got my goat again though. I'm sending what I believe to be perfectly good XML through to my pages which are being processed (YEY) but my doc isn't being picked up because it's claiming to not have a top level element :\ */
    ^^^ that error made no sense what so ever, it assumed nothing was being passed through when it blatently was. all i had to do was write the request to screen and this error vanished?!?

    this is what I have so far (might also be useful for anyone else doing this)

    Code:
       <%
       xmldata = "<?xml version=""1.0""?>" & vbnewline & _
       		"<a32>" & vbnewline & _
       		"<rootpf>" & vbnewline & _
       			"<to>a</to>" & vbnewline & _
       			"<to1>a</to1>" & vbnewline & _
       		"</rootpf>" & vbnewline & _
       		"<rootpf>" & vbnewline & _
       			"<to>a</to>" & vbnewline & _
       			"<to1>a</to1>" & vbnewline & _
       		"</rootpf>" & vbnewline & _
       		"</a32>"
       		
       '-----------------------------------------------------------------------------
       ' Connect to XML gateway
       '-----------------------------------------------------------------------------
       	sURI = "http://more2.alpha/systemsassurance/_new/test/xmlreceive.asp"
       	set oHTTP = Server.createObject("MSXML2.serverXMLHTTP")
       	oHTTP.open "post", sURI, false
       	oHTTP.setRequestHeader "Content-Type", "text/xml" 
       	oHTTP.send xmldata
       	
       '---------------------------------------------------------------------------------
       '- Load the response xml
       '---------------------------------------------------------------------------------
       	SET rdom = Server.CreateObject("microsoft.XMLDOM")
       	rdom.async = False
       	rdom.validateOnParse = False
       	rdom.resolveExternals = False
       	rdom.preserveWhiteSpace = True
       	
       	response.write server.htmlencode(oHTTP.responseTEXT)
       ' this works too --	response.write rdom.load(oHTTP.responseXML)
       %>
    and the receiver

    Code:
       <%
       set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
       xmldoc.async=false
       xmldoc.load(request)
       
     ' this one line fixed everything.
      response.write xmldoc.xml
      
      'for each x in xmldoc.documentElement.childNodes
      '	name = name & ", " & x.text
      'next
       
       	response.ContentType = "text/xml"
       	response.write "<a><b>[OK]</b></a>"
     'end if
       %>
    Don't you just hate it when it works first time.

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should echo the XML you send back atcha with a test node appended, give it a whirl:

    <%
    Response.ContentType = "text/xml"
    Set oDOM = Server.CreateObject("MSXML.DOMDocument")
    oDOM.load Request
    oDOM.selectSingleNode("rootThing").appendChild(oDOM.createElement("test")).text = "123"

    oDOM.save Response
    %>

  5. #5
    SitePoint Zealot manic's Avatar
    Join Date
    Dec 2001
    Location
    uk
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oDOM.save Response

    is that just used to send the response back? or does it do anything else?

    thanks for the example of other things I can do with the code too! it's appreciated. Not into creating / amending my own nodes yet but it could come up
    Don't you just hate it when it works first time.

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DOM.save Response

    This writes the xml structure to the response object - it's the best way to output XML that I've found.

    Doing this:
    response.write DOM.xml

    converts everything to UTF-8 which sometimes isn't what you want (can't have any accented characters in the xml)

  7. #7
    SitePoint Zealot manic's Avatar
    Join Date
    Dec 2001
    Location
    uk
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's very interesting. cheers for the info.
    Don't you just hate it when it works first time.

  8. #8
    SitePoint Zealot manic's Avatar
    Join Date
    Dec 2001
    Location
    uk
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a maximum limit on how much data can be received by "...load(request)" ? or reviewed with "response.write xmldoc.xml" ?

    When I run my own basic test XML through the above code it works fine and I can record the results in a database but when I switched to some more complex XML it receives nothing?! not sure why.

    the more complex XML looks a little like this:
    Code:
     
     	<paymentService version="1.4" merchantCode="TEST">
     
     	<notify>
     
     	<orderStatusEvent orderCode="0e">
     
     	<payment>
     <paymentMethod>VISA-SSL</paymentMethod>
     <amount value="10000" currencyCode="GBP" exponent="2" debitCreditIndicator="credit"/>
     <lastEvent>AUTHORISED</lastEvent>
     <CVCResultCode description="UNKNOWN"/>
     <AVSResultCode description="UNKNOWN"/>
     
     	<balance accountType="IN_PROCESS_AUTHORISED">
     <amount value="100" currencyCode="GBP" exponent="2" debitCreditIndicator="credit"/>
     </balance>
     <cardNumber>4111********1111</cardNumber>
     <riskScore value="0"/>
     </payment>
     
     	<journal journalType="AUTHORISED">
     
     	<bookingDate>
     <date dayOfMonth="10" month="08" year="2005"/>
     </bookingDate>
     
     	<accountTx accountType="IN_PROCESS_AUTHORISED" batchId="5">
     <amount value="100" currencyCode="GBP" exponent="2" debitCreditIndicator="credit"/>
     </accountTx>
     </journal>
     </orderStatusEvent>
     </notify>
     </paymentService>
    hope that comes out ok.
    Don't you just hate it when it works first time.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •