This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > March 2004 > How to parse XML returned by server





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to parse XML returned by server
Markus

2004-03-30, 10:13 pm

I need to parse an XML document I request from another server to input
the data into my SQl database. This is what I have so far and I get
this error:
Error Code: -2147024809
Reason: The parameter is incorrect.

when I try and repeat through the collection or print the length it is
0
For x = 0 to (objLst.length - 1)
but I can response.write sXML so I know I am getting the XML doc from
the server but how do I get it inot the new object to parse throught
it??

thanks so much for any help

Here is the code:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function createXMLobj()

' Create an xmlhttp object:
Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")
sURL = "http://www.domain.com"

' Opens the connection to the remote server.
xml.Open "GET", sURL , False

xml.SetRequestHeader "Content-type", "text/xml"

'Sends the request and returns the data:
xml.Send

'Cast it just in case
sXML = xml.responseText

set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
xmlObj.async = False
xmlObj.load(sXML)

'return true
createXMLobj = true

end function


if createXMLobj then
Dim x, objLst

Set objLst = Server.CreateObject("MSXML2.ServerXMLHTTP")
Set objLst = xmlObj.getElementsByTagName("*")

If xmlObj.parseError.errorCode <> 0 Then
'handle the error
Response.Write "Error Code: " & xmlObj.parseError.errorCode & "<BR>"
Response.Write "Reason: " & xmlObj.parseError.reason & "<BR>"
Response.Write "Line: " & xmlObj.parseError.line & "<BR>"
Response.Write "Line Pos: " & xmlObj.parseError.linePos & "<BR>"
Response.Write "Source Text: " & xmlObj.parseError.srcText & "<BR>"
End If


For x = 0 to (objLst.length - 1)
document.write(objLst.item(i).nodeName)
document.write(": ")
document.write(objLst.item(i).text
Next
end if
Martin Honnen

2004-03-30, 10:13 pm



Markus wrote:

> I need to parse an XML document I request from another server to input
> the data into my SQl database. This is what I have so far and I get
> this error:
> Error Code: -2147024809
> Reason: The parameter is incorrect.
>
> when I try and repeat through the collection or print the length it is
> 0
> For x = 0 to (objLst.length - 1)
> but I can response.write sXML so I know I am getting the XML doc from
> the server but how do I get it inot the new object to parse throught
> it??
>
> thanks so much for any help
>
> Here is the code:
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> function createXMLobj()
>
> ' Create an xmlhttp object:
> Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")
> sURL = "http://www.domain.com"
>
> ' Opens the connection to the remote server.
> xml.Open "GET", sURL , False
>
> xml.SetRequestHeader "Content-type", "text/xml"


Here you set a content type
>
> 'Sends the request and returns the data:
> xml.Send


but here you do not send any XML so why that content type above?
>
> 'Cast it just in case
> sXML = xml.responseText


Simply use
xml.responseXML
don't try to parse responseText again


--

Martin Honnen
http://JavaScript.FAQTs.com/

markus

2004-03-30, 10:13 pm

Ok I got it ..... thanks for the direction

function createXMLobj()

' Create an xmlhttp object:
'Set XML = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
'Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")
Set httpObj = Server.CreateObject("MSXML2.ServerXMLHTTP")
sURL = "http://www.domain.com/thisXML.xml"

' Opens the connection to the remote server.
httpObj.Open "GET", sURL , False

httpObj.SetRequestHeader "Content-type", "text/xml"

'Sends the request and returns the data:
httpObj.send

Set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
xmlObj.validateOnParse = True
xmlObj.loadXML httpObj.ResponseXML.xml 'load the XML that is returned from the send method into the XML DOM

'return true
createXMLobj = true

end function
Julian F. Reschke

2004-03-30, 10:13 pm

markus wrote:

> Ok I got it ..... thanks for the direction
>
> function createXMLobj()
>
> ' Create an xmlhttp object:
> 'Set XML = Server.CreateObject("Microsoft.XMLHTTP")
> ' Or, for version 3.0 of XMLHTTP, use:
> 'Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")
> Set httpObj = Server.CreateObject("MSXML2.ServerXMLHTTP")
> sURL = "http://www.domain.com/thisXML.xml"
>
> ' Opens the connection to the remote server.
> httpObj.Open "GET", sURL , False
>
> httpObj.SetRequestHeader "Content-type", "text/xml"
>
> 'Sends the request and returns the data:
> httpObj.send
>
> Set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
> xmlObj.validateOnParse = True
> xmlObj.loadXML httpObj.ResponseXML.xml 'load the XML that is returned from the send method into the XML DOM


Why not simply:

xmlObj = httpObj.ResponseXML

?

> ...


Regards, Julian
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews