Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 30th, 2007, 03:01 AM
dj__nj's Avatar
dj__nj dj__nj is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Location: Grantham, UK
Posts: 358 dj__nj User rank is Corporal (100 - 500 Reputation Level)dj__nj User rank is Corporal (100 - 500 Reputation Level)dj__nj User rank is Corporal (100 - 500 Reputation Level)dj__nj User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 14 h 27 m 28 sec
Reputation Power: 6
Post classic ASP: import remote XML file into database

If any body would like it below is my full complete code to get XML data and store it into an access database.

Code:
<%
Dim XMLDom
      Dim ItemID
      Dim DbConn
      Dim SQLString
      Dim ANArticleNode
      Dim CollectionOfArticleNodes
	  
Set DbConn = Server.Createobject("ADODB.connection")

	DbConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="
 	DbConn.ConnectionString = DbConn.ConnectionString + server.MapPath("databasename")

    DbConn.Open
	Set XMLDom = Server.CreateObject( "Msxml2.DOMDocument.3.0" )
	XMLDom.async = false
	XMLDom.Load ("feed address goes here")

	Set CollectionOfArticleNodes = XMLDom.SelectNodes("InfoStreamResults/Article")
	'-- Iterate the collection of Article Tags 
	For Each ANArticleNode in CollectionOfArticleNodes 
    ItemID = ANArticleNode.SelectSingleNode("@ID").text
    Heading = ANArticleNode.SelectSingleNode("Heading").text 
    Contents = ANArticleNode.SelectSingleNode("Contents").text
    sDate = ANArticleNode.SelectSingleNode("Date").text 
    '-- Delete the item from the local database if it exists
    SQLString = "DELETE FROM NewsData WHERE DirectNewsID=" & ItemID & ";" 
	'response.Write(SQLString)
    DbConn.Execute(SQLString)
    '-- Insert the item into the local database
   SQLString = "INSERT INTO NewsData ([DirectNewsID], [Heading] ,[Contents], [Date]) VALUES(" & ItemID &", '" & EncodeIt(Heading) & "', '"& EncodeIt(Contents) & "', #"& sDate & "#)"
   'response.Write(SQLString)
   DbConn.Execute(SQLString)
   Next

Function EncodeIt(ByVal TextString)
   TextString = Replace(TextString, "'", "''")
   TextString = Replace(TextString, Chr(34), Chr(34)&Chr(34))
   EncodeIt = TextString
End Function
%>


What the code does is first it deletes any entry in the database which is currently on the XML sheet and then it runs the insert to enter all of the data into the DB. It runs a delete first so that there are no double entries in the database.

Hope someone may find this helpful.
Comments on this post
Shadow Wizard agrees!

Last edited by Shadow Wizard : January 30th, 2007 at 03:30 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > classic ASP: import remote XML file into database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway