View Single Post
  #2 (permalink)  
Old Dec 5th, 2005, 10:31
fogofogo fogofogo is offline
Junior Member
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selecting certain XML elements

problem solved
If anyone is interested, here is the solution:
Code: Select all
Dim XMLDom
Dim ItemID
Dim DbConn
Dim SQLString
Dim ANArticleNode
Dim ANArticleNode2
Dim CollectionOfArticleNodes
Dim CollectionOfArticleNodes2
Dim cst
Set XMLDom = CreateObject("MSXML2.DomDocument.4.0")
XMLDom.async = False
XMLDom.setProperty "ServerHTTPRequest", True
Set DbConn = Createobject("adodb.connection")
DbConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=test1.mdb"
'-- Load the XML data from your live URL
XMLDom.Load("http://feeds.directnews.org.uk/?ad96...2-ad546b2ed850") 
'-- Create a reference to a collection of all Article Tags within the downloaded XML Document
Set CollectionOfArticleNodes = XMLDom.SelectNodes("InfoStreamResults/Article")
'-- Iterate the collection of Article Tags 
For Each ANArticleNode in CollectionOfArticleNodes 
 '-- Now create a reference to the category tag
 Set CollectionOfArticleNodes2 = ANArticleNode.SelectNodes("Categories/Category")
 '-- And iterate through the nodes to test for a match
 For Each ANArticleNode2 in CollectionOfArticleNodes2
  ItemID = ANArticleNode2.SelectSingleNode("@ID").text
  if ItemID = "430009735" then
   '-- Retrieve the value of the heading node from the current article
   Heading = ANArticleNode.SelectSingleNode("Heading").text
 
   '-- Insert the item into the local database
   SQLString = "INSERT INTO test (Heading) " _
   & "VALUES('" & EncodeIt(Heading) & "');" 
   DbConn.Execute(SQLString) 
  end if
 Next '-- check the next category ID
Next '-- move to the next article
'-- Handles quotations in text
Function EncodeIt(TextString)
 TextString = Replace(CStr(TextString), "''", "'")
 TextString = Replace(TextString, "'", "''")
 EncodeIt = TextString
End Function
%>
Reply With Quote