S
Subrato
Hi,
I am very new to xml and I have this piece of code which I took off
a website. The situation is that on of the website, user files up a
form and it is submitted. On submission, the page should do a xml post
to my site. On receiving the xml on my end, I take that data and
insert it into sql server table. I dont know whats missing . Here is
the piece of code I use for my testing.
'Sending
<%
RequestorFirstName = "Tony"
RequestorLastName = "Topper"
RequestorEmail = "(e-mail address removed)"
RequestorAddress1 = "Top Address"
RequestorAddress2 = "High Lane"
RequestorCity = "New Haven"
RequestorState = "Connecitcut"
RequestorCountry = "USA"
RequestorZip = "06511"
RequestorContactFlag = "Yes"
RequestorInterestedBoat = "Laser,Nomad"
RequestorOwnership = "No"
RequestorActivities = "Saltwater Fishing, General Fitness"
RequestorBoatList = "Air Boats,Fish and Ski,Multi-Hull
Cruisers,Electric Boats"
RequestorPurchaseTimeLine = "As soon as possible"
Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "GET", "http://someserver:9099/example.xml", false
xmlHttp.send()
xmlDoc=xmlHttp.responseText
firstname = RequestorFirstName
lastname = RequestorLastName
xmlDoc = replace(xmlDoc,"[FirstName]",firstname)
xmlDoc = replace(xmlDoc,"[LastName]",lastname)
xmlDoc = replace(xmlDoc,"[Line1]",RequestorAddress1)
xmlDoc = replace(xmlDoc,"[Line2]",RequestorAddress2)
xmlDoc = replace(xmlDoc,"[City]",RequestorCity)
xmlDoc = replace(xmlDoc,"[StateProvinceCode]",RequestorState)
xmlDoc = replace(xmlDoc,"[PostalCode]",RequestorZip)
xmlDoc =
replace(xmlDoc,"[date]",FormatDateTime(date(),vbshortdate))
xmlDoc = replace(xmlDoc, "[ContactFlag]", RequestorContactFlag)
xmlDoc = replace(xmlDoc, "[InterestedInKnownBoat]",
RequestorInterestedBoat)
xmlDoc = replace(xmlDoc, "[Ownership]", RequestorOwnership)
xmlDoc = replace(xmlDoc, "[Activities]", RequestorActivities)
xmlDoc = replace(xmlDoc, "[BoatList]", RequestorBoatList)
xmlDoc = replace(xmlDoc, "[PurchaseTimeline]",
RequestorPurchaseTimeLine)
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Notice the two changes in the next two lines:
xml.Open "POST", "http://someserver:9099/xmlimport.asp", False
xml.setRequestHeader "Content-Type", "application/x-www-form-
urlencoded"
xml.Send xmlDoc
'Response.Write( xml.responseText)
pos = ""
pos=InStr( xml.responseText,"<OrderRejectionMessage></
OrderRejectionMessage>")
'check rejection if error send email
if pos <> "" then
verror = "success"
else
verror = "error"
end if
Response.Write(verror)
%>
On receiving end
Set objXMLDOM = Server.CreateObject("MSXML2.DOMDocument")
objXMLDOM.setProperty "ServerHTTPRequest", True
objXMLDOM.async = False
Check = objXMLDOM.load(Request)
Response.Write(Check & "11111")
objXMLDOM.Save("http://someotherserver:9099/xml/xmldoc.xml")
'This just writes out the posted xml, but we could process it
here
Response.Write objXMLDOM
Set objLst = objXMLDOM.getElementsByTagName("*")
For i = 0 to (objLst.length) -1
if objLst.item(i).nodeName = "FirstName" then
RequestorFirstName = objLst.item(i).text
End if
if objLst.item(i).nodeName = "LastName" then
RequestorLastName = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Email" then
RequestorEmail = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Line1" then
RequestorAddress1 = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Line2" then
RequestorAddress2 = objLst.item(i).text
End if
if objLst.item(i).nodeName = "City" then
RequestorCity = objLst.item(i).text
End if
if objLst.item(i).nodeName = "StateProvinceCode" then
RequestorState = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Country" then
RequestorCountry = objLst.item(i).text
End if
if objLst.item(i).nodeName = "PostalCode" then
RequestorZip = objLst.item(i).text
End if
if objLst.item(i).nodeName = "ContactFlag" then
RequestorContactFlag = objLst.item(i).text
End if
if objLst.item(i).nodeName = "InterestedInKnownBoat" then
RequestorInterestedBoat = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Ownership" then
RequestorOwnership = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Activities" then
RequestorActivities = objLst.item(i).text
End if
if objLst.item(i).nodeName = "BoatList" then
RequestorBoatList = objLst.item(i).text
End if
if objLst.item(i).nodeName = "PurchaseTimeline" then
RequestorPurchaseTimeLine = objLst.item(i).text
End if
if objLst.item(i).nodeName = "date" then
RequestorDate = objLst.item(i).text
End if
Next
%>
I am unable to understand whats wrong or missing in this piece of code
I am very new to xml and I have this piece of code which I took off
a website. The situation is that on of the website, user files up a
form and it is submitted. On submission, the page should do a xml post
to my site. On receiving the xml on my end, I take that data and
insert it into sql server table. I dont know whats missing . Here is
the piece of code I use for my testing.
'Sending
<%
RequestorFirstName = "Tony"
RequestorLastName = "Topper"
RequestorEmail = "(e-mail address removed)"
RequestorAddress1 = "Top Address"
RequestorAddress2 = "High Lane"
RequestorCity = "New Haven"
RequestorState = "Connecitcut"
RequestorCountry = "USA"
RequestorZip = "06511"
RequestorContactFlag = "Yes"
RequestorInterestedBoat = "Laser,Nomad"
RequestorOwnership = "No"
RequestorActivities = "Saltwater Fishing, General Fitness"
RequestorBoatList = "Air Boats,Fish and Ski,Multi-Hull
Cruisers,Electric Boats"
RequestorPurchaseTimeLine = "As soon as possible"
Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "GET", "http://someserver:9099/example.xml", false
xmlHttp.send()
xmlDoc=xmlHttp.responseText
firstname = RequestorFirstName
lastname = RequestorLastName
xmlDoc = replace(xmlDoc,"[FirstName]",firstname)
xmlDoc = replace(xmlDoc,"[LastName]",lastname)
xmlDoc = replace(xmlDoc,"[Line1]",RequestorAddress1)
xmlDoc = replace(xmlDoc,"[Line2]",RequestorAddress2)
xmlDoc = replace(xmlDoc,"[City]",RequestorCity)
xmlDoc = replace(xmlDoc,"[StateProvinceCode]",RequestorState)
xmlDoc = replace(xmlDoc,"[PostalCode]",RequestorZip)
xmlDoc =
replace(xmlDoc,"[date]",FormatDateTime(date(),vbshortdate))
xmlDoc = replace(xmlDoc, "[ContactFlag]", RequestorContactFlag)
xmlDoc = replace(xmlDoc, "[InterestedInKnownBoat]",
RequestorInterestedBoat)
xmlDoc = replace(xmlDoc, "[Ownership]", RequestorOwnership)
xmlDoc = replace(xmlDoc, "[Activities]", RequestorActivities)
xmlDoc = replace(xmlDoc, "[BoatList]", RequestorBoatList)
xmlDoc = replace(xmlDoc, "[PurchaseTimeline]",
RequestorPurchaseTimeLine)
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Notice the two changes in the next two lines:
xml.Open "POST", "http://someserver:9099/xmlimport.asp", False
xml.setRequestHeader "Content-Type", "application/x-www-form-
urlencoded"
xml.Send xmlDoc
'Response.Write( xml.responseText)
pos = ""
pos=InStr( xml.responseText,"<OrderRejectionMessage></
OrderRejectionMessage>")
'check rejection if error send email
if pos <> "" then
verror = "success"
else
verror = "error"
end if
Response.Write(verror)
%>
On receiving end
Set objXMLDOM = Server.CreateObject("MSXML2.DOMDocument")
objXMLDOM.setProperty "ServerHTTPRequest", True
objXMLDOM.async = False
Check = objXMLDOM.load(Request)
Response.Write(Check & "11111")
objXMLDOM.Save("http://someotherserver:9099/xml/xmldoc.xml")
'This just writes out the posted xml, but we could process it
here
Response.Write objXMLDOM
Set objLst = objXMLDOM.getElementsByTagName("*")
For i = 0 to (objLst.length) -1
if objLst.item(i).nodeName = "FirstName" then
RequestorFirstName = objLst.item(i).text
End if
if objLst.item(i).nodeName = "LastName" then
RequestorLastName = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Email" then
RequestorEmail = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Line1" then
RequestorAddress1 = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Line2" then
RequestorAddress2 = objLst.item(i).text
End if
if objLst.item(i).nodeName = "City" then
RequestorCity = objLst.item(i).text
End if
if objLst.item(i).nodeName = "StateProvinceCode" then
RequestorState = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Country" then
RequestorCountry = objLst.item(i).text
End if
if objLst.item(i).nodeName = "PostalCode" then
RequestorZip = objLst.item(i).text
End if
if objLst.item(i).nodeName = "ContactFlag" then
RequestorContactFlag = objLst.item(i).text
End if
if objLst.item(i).nodeName = "InterestedInKnownBoat" then
RequestorInterestedBoat = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Ownership" then
RequestorOwnership = objLst.item(i).text
End if
if objLst.item(i).nodeName = "Activities" then
RequestorActivities = objLst.item(i).text
End if
if objLst.item(i).nodeName = "BoatList" then
RequestorBoatList = objLst.item(i).text
End if
if objLst.item(i).nodeName = "PurchaseTimeline" then
RequestorPurchaseTimeLine = objLst.item(i).text
End if
if objLst.item(i).nodeName = "date" then
RequestorDate = objLst.item(i).text
End if
Next
%>
I am unable to understand whats wrong or missing in this piece of code