kessa
03-07-2007, 08:39 AM
Hi All,
I wonder if someone may be able to help me with the following - I'm part way there, but am getting stuck at the last hurdle.
I'm trying to integrate an XML feed from an external site into my site, and want to be able to compare the XML feed against our DB for the following:
check the XML feed against our DB to see if a property already exist in our DB - if it doesn't then I want to create it as a new record.
check the XML feed against our DB to see if a property already exists in our DB - if it does then I want to update the existing record in our DB.
check our DB for any properties which are not in the XML feed (which may be the case if the supplier of the XML data has removed a property) - if a property exists in our DB, but no longer exists in the XML feed I want update the record (not delete)
I've managed to get parts 1 & 2 working, but I'm not sure how to address part 3.
Here's a copy of the code I'm using so far:
<% Set domDoc = server.CreateObject("MSXML.DOMDocument")
domDoc.async = False ' load all of the XML file first
aFilename = server.MapPath("../file.xml")
if NOT domDoc.Load(aFilename) then
response.write "Could not load file " & afilename & "<br />"
response.end
end if
Set aNode = domDoc.documentElement
%>
<html>
<head>
</head>
<meta name="robots" content="noindex, nofollow" />
<body>
<%
housecount = 0
Set XMLHouses = domDoc.SelectNodes("Houses/House")
for each XMLHouse in XMLHouses
abort=0 'set the abort value to everything initially being OK
updateprop=0 ' this will be used to determine if the property should be created or updated
createprop=0 ' this will be used to determine if the property should be created or updated
Set XMLPropCode = domDoc.SelectSingleNode("Houses/House[" & housecount & "]/Code")
' first, check to make sure there is a property number in the XML feed, then check the propery code to see if it already exists in the DV database.
' if the property already exists then UPDATE record, if it doesn't then CREATE record.
if XMLPropCode.Text="" then
abort=1
response.write ("*** Abort"& XMLPropCode.Text&" - Error Location: No Property Number ***<br />")
else
strsql= "SELECT DBpropertycode FROM properties WHERE DBpropertycode='" & XMLPropCode.Text &"'"
set rs_property_code = objconn.execute(strsql)
if not rs_property_code.eof then
updateprop=1
response.write("This property already exist - update the record instead<br />")
else
createprop=1
response.write("This property doesn't already exist - go ahead and create a new record<br />")
end if
response.write "The property code is: " & XMLPropCode.Text & "<br />"
end if
if abort=1 then response.write ("*** This property was aborted ***<br />")
housecount = housecount + 1
next
' close all of the items
XMLPropCode.close
set XMLPropCode = nothing
%>
</body>
</html>
Thanks
Kessa
I wonder if someone may be able to help me with the following - I'm part way there, but am getting stuck at the last hurdle.
I'm trying to integrate an XML feed from an external site into my site, and want to be able to compare the XML feed against our DB for the following:
check the XML feed against our DB to see if a property already exist in our DB - if it doesn't then I want to create it as a new record.
check the XML feed against our DB to see if a property already exists in our DB - if it does then I want to update the existing record in our DB.
check our DB for any properties which are not in the XML feed (which may be the case if the supplier of the XML data has removed a property) - if a property exists in our DB, but no longer exists in the XML feed I want update the record (not delete)
I've managed to get parts 1 & 2 working, but I'm not sure how to address part 3.
Here's a copy of the code I'm using so far:
<% Set domDoc = server.CreateObject("MSXML.DOMDocument")
domDoc.async = False ' load all of the XML file first
aFilename = server.MapPath("../file.xml")
if NOT domDoc.Load(aFilename) then
response.write "Could not load file " & afilename & "<br />"
response.end
end if
Set aNode = domDoc.documentElement
%>
<html>
<head>
</head>
<meta name="robots" content="noindex, nofollow" />
<body>
<%
housecount = 0
Set XMLHouses = domDoc.SelectNodes("Houses/House")
for each XMLHouse in XMLHouses
abort=0 'set the abort value to everything initially being OK
updateprop=0 ' this will be used to determine if the property should be created or updated
createprop=0 ' this will be used to determine if the property should be created or updated
Set XMLPropCode = domDoc.SelectSingleNode("Houses/House[" & housecount & "]/Code")
' first, check to make sure there is a property number in the XML feed, then check the propery code to see if it already exists in the DV database.
' if the property already exists then UPDATE record, if it doesn't then CREATE record.
if XMLPropCode.Text="" then
abort=1
response.write ("*** Abort"& XMLPropCode.Text&" - Error Location: No Property Number ***<br />")
else
strsql= "SELECT DBpropertycode FROM properties WHERE DBpropertycode='" & XMLPropCode.Text &"'"
set rs_property_code = objconn.execute(strsql)
if not rs_property_code.eof then
updateprop=1
response.write("This property already exist - update the record instead<br />")
else
createprop=1
response.write("This property doesn't already exist - go ahead and create a new record<br />")
end if
response.write "The property code is: " & XMLPropCode.Text & "<br />"
end if
if abort=1 then response.write ("*** This property was aborted ***<br />")
housecount = housecount + 1
next
' close all of the items
XMLPropCode.close
set XMLPropCode = nothing
%>
</body>
</html>
Thanks
Kessa