Forum Moderators: open

Message Too Old, No Replies

Reading posted XML

         

f00sion

4:50 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



I have been using xml off and on for a while now and have posted xml files and read back responses from servers using xmlhttp but now a customer wants to post an xml document to us so we can send back some info.. I hadn't ever thought about this before but how do I retrieve that information in my asp page? The only solution I could come up with is if the client puts the document inside a form variable.
So i would read it like this:
strxml = request.form("xml")
It seems a little odd for them to have to do it this way as I never have in my experiences, am I missing something? Maybe an asp page isnt the solution that I am looking for?

BlobFisk

5:12 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What about an XSLT to transform the XML document into a format that can be read by a browser? No need for ASP at all...

korkus2000

5:26 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So how are they sending it, or want to send it?

f00sion

5:32 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



this is similar to the code they will be using:

set objXML = server.createobject("msxml2.serverxmlhttp")
set xmldom = server.CreateObject("msxml2.domdocument")
objXML.Open "POST","http://myserver/somepage.asp", False
objxml.setrequestheader "Accept-Language", "en"
objxml.setrequestheader "Connection","Keep-Alive"
objXML.setrequestheader "Content-Type","application/x-www-form-urlencoded"
objxml.send somexmlstring

so my question is in somepage.asp how to i read the xml that they posted?

macrost

5:47 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



Well it all depends on what you will be doing with the xml that is sent to you. If you are displaying the xml, then you can load the xml and xsl into the MSXML2.FreeThreadedDOMDocument.3.0 and use msxml2.xsltemplate to transform in memory. The problem with this is, by loading the xml that is sent from their server, it will turn it into a double byte wide string. utf-16 if I'm correct.

Mac

f00sion

5:51 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



I need to read the xml (requests for order statuses) and return xml based on the database results. but how would i load the xml into the dom object?

mattglet

9:14 pm on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xml.loadXml(XML_DOC_GOES_HERE)

-Matt

RossWal

9:29 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



This is an interesting question f00sion. Please post your solution when you get there. The XMLHTTP post will allow you to post name/value pairs. I think those would look just like a form collection on the receiving end, so you would retrieve them just like a form variable. If you post the whole thing as a big blob, without the name value pair, there must be a straight forward way to pull the stuff out of the request object. Like you, I've posted but never retrieved, but I may need to retrieve soon.

f00sion

11:21 pm on Sep 19, 2003 (gmt 0)

10+ Year Member



Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xml.loadXml(XML_DOC_GOES_HERE)

The problem is the XML_DOC_GOES_HERE part, if it was posted as a blob, like ross said, is it possible to retrieve in the page?

right now im thinking the only solution is to have them do
objxml.send "xml=" & somexmlstring
then i can just load the dom through request.form but it doesnt seem like the right way to do it. I have posted this question on multiple different messageboards but nobody has been able to come up with an answer; like i said maybe asp just isnt suited for this?

mattglet

9:08 pm on Sep 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



are you looking to read the xml via browser, or save to file, or?

if you are just looking to read to the info to browser, just format the info via XSL.

forgive me if i'm missing something...

-Matt

RossWal

4:16 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



I believe he's trying to read it server side to do some processing. Normally in ASP, posted data is accessible to the ASP script as a collection of name/value pairs representing the stuff on the form that was posted. The question seems to be, if a big chunk of data is posted without name/value pairs, how can you pull the chunk into the ASP script?

aspdaddy

7:17 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried:

objxml.send "somexmlstring=" & somexmlstring

reading page:
somexmlstring = request("somexmlstring")

f00sion

9:32 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



that is the only solution i have been able to come up with..but it seems weird and I know it can be done without that in other implementations, just trying to find out of it is possible with asp.

f00sion

9:41 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



got it all worked out! For anybody who is interested here it is:

set objXML = server.createObject("msxml2.domdocument")
objxml.load Request

so simple i would have never thought to try it.

mattglet

2:02 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you use:

Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")

i'm pretty sure you'll have better performance.

-Matt

macrost

4:21 pm on Sep 25, 2003 (gmt 0)

10+ Year Member



Mattglet is right, if you use the freethreadeddomdocument, you will have better performance if you have a good sized amout of memory on your server.

Mac

sbl70

7:09 pm on Oct 31, 2003 (gmt 0)

10+ Year Member



Hi All-

The "objXML.Load" method will also most likely give you an error if you are streaming XML from a URL. You might want to try the following when streaming data from another server, data source, etc. This page could be used to process a request from a form or a direct link to a URL. I would call this page something like "xml_processing.asp".

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Dim objXML, objXmlDoc, strUrl, strDataStream, strXmlFile

[b]' Check to see if you are loading file from a form[/b]

strXmlFile = Request.Form("txtSomeXmlFile")

If strXmlFile = "" Then

Set objXML = Server.CreateObject("Msxml2.ServerXMLHTTP")

[b]' Make sure we can get the data[/b]

If IsObject(objXML) Then

[b]' The page could be a straight forward page like sompage.asp[/b]

'strUrl = "somepage.asp"

[b]' Or with some XML parameters attached to the QueryString[/b]

strUrl = "somepage.asp?Cust=<customer>Joe Smith</customer>"

[b]' Secure open method with authentication[/b]

'objXML.Open "GET", strUrl, False, "Domain\Username", "Password"

[b]' Open method without authentication[/b]

objXML.Open "GET", strUrl, False 

objXML.Send() 

strDataStream = objXML.ResponseText

Else

Response.Write "Cannot make ServerXMLHTTP Object."

End If

End If

[b]' Make sure we have data to read[/b]

If strDataStream <> "" Then

Set objXmlDoc = CreateObject("Msxml2.DOMDocument")

objXmlDoc.Async = False

objXmlDoc.ValidateOnParse = False

objXmlDoc.ResolveExternals = False

[b]' If the XML is being streamed from another source[/b]

objXmlDoc.LoadXML(strDataStream)

ElseIf strXmlFile <> "" Then

[b]' If the XML is from the XML document strXmlFile[/b]

'objXmlDoc.load(strXmlFile)

Else

Response.Write "No XML data was able to be retrieved and parse!

End If

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

I have a VBScript that I use to traverse the XML document and use a Response.Write to write to the screen. If you'd like more info on it, reply back to this post and I'll post it.

Hope this gave some more insight on this. BTW...sorry for the lack of indenting, I could figure out how to acieve that.

Scott