473,383 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

xml positng and receiving code ?

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 = "to********@topping.com"
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

Apr 19 '07 #1
1 2653

"Subrato" <mu**************@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
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.
Comments in line
'Sending

<%
RequestorFirstName = "Tony"
RequestorLastName = "Topper"
RequestorEmail = "to********@topping.com"
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")
Don't use the XMLHTTP in ASP, its not thread safe, use
MSXML2.ServerXMLHTTP.3.0 instead.
xmlHttp.open "GET", "http://someserver:9099/example.xml", false
xmlHttp.send()
xmlDoc=xmlHttp.responseText
I doubt the above roundtrip to your server is necessary just use:-

Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
xmlDoc.LoadXML "<root />"

If it is necessary for some other reason than to get the placemarks you are
using (which I'll correct below) then make sure the file is valid XML and
use:-

Set xmlDoc = xmlHttp.ResponseXML
firstname = RequestorFirstName
lastname = RequestorLastName
Why??
xmlDoc = replace(xmlDoc,"[FirstName]",firstname)
You should not attempt to create XML using a string. If you use the above
technique and the string being inserted happens to contain a < or & or some
other character of special meaning to XML the document will be corrupt.

Instead you should use a DOMDocument (as created above) to build your XML.
I use the following standard function to make building XML easier:-

Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function

With this function present the code above becomes:-

AddElem xmlDoc.documentElement, "FirstName", RequestorFirstName
xmlDoc = replace(xmlDoc,"[LastName]",lastname)
AddElem xmlDoc.documentElement, "FirstName", RequestorLastName
xmlDoc = replace(xmlDoc,"[Line1]",RequestorAddress1)
and so on...
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")
Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
>
' 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"
Don't use the above header you're sending XML. Use:-

xml.setRequestHeader "Content-Type", "test/xml; CharSet=UTF-8"

OR don't bother with the header at all.
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
The ServerHTTPRequest property is not necessary. You are not making a
request; the content has already arrived and is in the Request object.
objXMLDOM.async = False
Check = objXMLDOM.load(Request)
This is ok.
Response.Write(Check & "11111")
Whats the "11111" about?
objXMLDOM.Save("http://someotherserver:9099/xml/xmldoc.xml")
You cannot save to a URL. Is this yet another server to which the XML
should be passed to?
If so you should use the ServerXMLHTTP object to post the XML as you've done
form the origin.

BTW, don't use parentheses in method or procedure calls that aren't
returning any value.
>
'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
I prefer to use another function to retrieve the text value of a path:-

Function GetNodeText(roContext, rsPath)
Dim oNode

Set oNode = roContext.SelectSingleNode(rsPath)

If Not oNode Is Nothing Then
GetNodeText = oNode.Text
Else
GetNodeText = Null
End If
End Function

Now you can use the following code to retrieve the values:-

Dim oRoot : Set oRoot = objXMLDOM.documentElement

RequestorFirstName = GetNodeText(oRoot, "FirstName")
if objLst.item(i).nodeName = "LastName" then
RequestorLastName = objLst.item(i).text
End if
RequestorFirstName = GetNodeText(oRoot, "LastName")
if objLst.item(i).nodeName = "Email" then
RequestorEmail = objLst.item(i).text
End if
and so on..
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
Since you are using SQL Server consider passing the XML String to SQL Server
as parameter and using the OPENXML clause to retrieve the values from it.

One other note is on the date format used in the XML. I use dd-mmm-yyyy
(where mmm is the abbrevieated month name) which is parseable unambiguously
by VBScript, JScript and SQL Server.

Anthony.
Apr 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ramiro Barbosa, Jr. | last post by:
All, In regards to the call below, I was wondering why is it that the 'szMessage' receiving buffer results in an empty one, but by printing 'ret' it indicates the number of bytes I am indeed...
3
by: Stephan Steiner | last post by:
Hi I have a small program listening to UDP broadcast datagrams that are periodically sent out. It will stop listening for a certain period if either a sufficient number of packets has been...
0
by: André Betz | last post by:
Hi, I've established a TCP-Socket Connection and now I want to receive datas. So I called BeginReceive where I set the receiving buffer and length. Now in the asynchronous CallBack-Function I...
5
by: Danny | last post by:
I am working on a project in which a number of client applications will be posting xml documents as a byte array to an ASP.NET page on our web server. I am trying to simulate the process and run...
0
by: Danny | last post by:
I am working on a project in which a number of client applications will be posting xml documents as a byte array to an ASP.NET page on our web server. I am trying to simulate the process and run...
1
by: greenxiar | last post by:
My code is below and the platform is Win2K3 R2: using System; using System.Net; using System.Net.Sockets; using System.Threading; namespace TechUDPBroadcast { class Program { static void...
2
by: pauland80 | last post by:
Hello, My soft passively listen to a device sending +- 300 bytes of data each second. After several hours of work, the soft abruptly stops receiving data without any error, (while the device...
7
by: darthghandi | last post by:
I am having mixed results with asynchronous socket receives. Sometimes I get the right information back from the buffer, other times I get some of the data that should be in the buffer printed out...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.