Anthony,
Yes, I followed your directions and here is the new code. The funny part is
I think i used the same way as I coded before and how come it suddenly
doesn't work any more.
Now I tried to debug the xml file step by step. so my xml file first will
look like this:
<?xml version="1.0" encoding="UTF-8" ?>
<enrollment orderID="200808251114527143" PONumber="50000" marketingCode="E"
productName="adventureCenter">
</enrollment>
Ok, no xml needs a top element error message.
so I changed the xml file to:
<?xml version="1.0" encoding="UTF-8" ?>
<enrollment orderID="200808251114527143" PONumber="50000" marketingCode="E"
productName="adventureCenter">
<test>Y</test>
</enrollment>
Only one extra line: <test>Y</test> besides the top element.
Now it complains again:
<xmlResponse>
<isSuccess>False</isSuccess>
<errorField>XML</errorField>
−
<errorMessage>
error code: -1072896680 reason: XML document must have a top level element.
line #: 0
</errorMessage>
<policyNumber/>
</xmlResponse>
It seems it only takes a top level element xml file, as soon as I add one
more line to the xml file, it starts to complain. I don't get it.
'*************************************
Server side:
'*************************************
Dim xmlDoc, InstreamXMLRoot, TestFlag
Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument.3.0 ") '8/23/2008
xmlDoc.async = false
xmlDoc.Load Request '--this is for xml sent via body
Response.ContentType = "text/xml" '--for testing program
If xmlDoc.parseError.errorCode <> 0 Then
Call UpdateXMLResponse(orderID, "False", "XML", "error code: "
&xmlDoc.parseError.errorCode & " reason: " &xmlDoc.parseError.reason &" line
#: " &xmlDoc.parseError.line , "")
End If
IF isNULL(xmlDoc) Then
Set InstreamXMLRoot=Nothing
Call UpdateXMLResponse(orderID, "False", "XML", "The server didn't receive
the XML stream", "")
END IF
Set InstreamXMLRoot=xmlDoc.documentElement
IF isNULL(InstreamXMLRoot) Then
Set InstreamXMLRoot=Nothing
Call UpdateXMLResponse(orderID, "False", "XML", "The server didn't receive
the XML stream", "")
END IF
'Save all info before any transaction
xmlDoc.Save(Server.MapPath("B2BResponse/" & hour(now) & "_" & minute(now) &
"_" & RandomNumber(1000000) & "_" & month(now) & "_" & day(now) & "_" &
year(now) &"_B2BResponse.xml"))
'check if this is production transaction
Call UpdateXMLResponse(orderID, "False", "XML", "The server received the XML
stream", "")
'************************************************* ************
' Update B2B Response ''Response.ContentType="text/xml"
'************************************************* ************
Function UpdateXMLResponse(byVal order_id, byVal SuccFlag, byVal ErrField,
byVal Desc, byVal PolicyNum)
'Set RespInfo=Server.CreateObject("Microsoft.XMLDOM")
Set RespInfo=CreateObject("MSXML2.DOMDocument.3.0")
RespInfo.async=False
RespInfo.load(server.MapPath("/Utility/B2BResponse.xml"))
Set RespInfoRoot=RespInfo.documentElement
Set SuccessNode=RespInfoRoot.selectSingleNode("isSucce ss")
SuccessNode.Text=SuccFlag
If SuccFlag="True" Then
Set PolicyNode=RespInfoRoot.selectSingleNode("policyNu mber")
PolicyNode.Text=PolicyNum
Else
Set ErrNode=RespInfoRoot.selectSingleNode("errorField" )
ErrNode.Text=ErrField
Set DescNode=RespInfoRoot.selectSingleNode("errorMessa ge")
DescNode.Text=Desc
End If
If order_id <>"" Then
RespInfo.save(server.MapPath("B2BResponse/" & order_id &"_B2BResponse.xml"))
Else
RespInfo.save(server.MapPath("B2BResponse/" & month(now) & "_" & day(now)
& "_" & RandomNumber(1000000) & "_" & year(now) &"_B2BResponse.xml"))
End If%>
<%
Response.ContentType = "text/xml"
Response.Write RespInfo.xml
Set RespInfo=Nothing
Response.End
End Function
'****************************
B2Bresponse.xml is like this:
'****************************
<xmlResponse>
<isSuccess />
<errorField />
<errorMessage />
<policyNumber />
</xmlResponse>
'**********************
Client side program is like this:
'**********************
<%@ Language=vbScript%>
<%
'Set xmlDom=CreateObject("Microsoft.XMLDOM")
set xmlDom=CreateObject("MSXML2.DOMDocument.3.0")
XMLDom.async =False
xmlDom.load Server.MapPath("08242008ACTest.xml")
dim xmlhttp
set xmlhttp=server.CreateObject("MSXML2.ServerXMLHTTP. 3.0") '8/23/2008
xmlhttp.Open
"POST","https://www.travelinsuranceservices.com/ac/xt_ac_B2B.asp",false
xmlhttp.send xmlDom '8/23/2008
if(Err <> 0) then
Response.Write("An error occured when retrieving data from an external
source.<br />")
Response.Write(Err.Description)
Response.End
end if
On error goto 0
'if request is not Ok then display detailed message about the request
problem
if(xmlHttp.status <> 200) then
Response.Write("The remote server returned an invalid statuscode: #8221;"
& _
xmlHttp.status & " " & xmlHttp.statusText) & "<br>"
Response.Write("response text from remote server" & _
" " & xmlHttp.responseText)
Response.End
end if
if xmlHttp.responseXML is nothing then
Response.Write("The remote server didn’t return xml content.")
Response.End
end if
Response.ContentType = "text/xml"
Response.CharSet = "UTF-8"
'Response.Write xmlhttp.responsexml.xml
xmlhttp.responseXML.save Response
Set xmlhttp = nothing
%>
--
Betty
"Anthony Jones" wrote:
> "c676228" <> wrote in message
> news:408B95A3-DD9A-454F-B0DD-...
> > Hi all,
> >
> > I had a program and it always works fine and suddenly it gives me the
> > following message when a pass a xml file to our server program:
> > error code: -1072896680 reason: XML document must have a top level
> element.
> > line #: 0
> > I don't know if it is my xml file or it is something else?
> >
>
> <snip>
>
> >
> > Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
>
>
> D'oh! I think I see it now try inserting the following here:-
>
> xmlDoc.async = false
>
> > xmlDoc.Load Request '--this is for xml sent via body
> >
> > Response.ContentType = "text/xml" '--for testing program
>
> <snip>
>
>
> I still think you should make the other tweaks I recommended as well. 
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>
>