944,042 Members | Top Members by Rank

Dec 2nd, 2005
0

selecting certain xml elements

Expand Post »
Hello All,

I have a question regarding searching and selecting certain elements in an XML document using asp. The xml script basically consist of news headings, contents, date, and category elements that tell what the news is related to and where it should be displayed and stored. For example Finance catagory stories will be stored in a different database to the business one.

RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. <Article Created="16:01:59" ID="15105602">
  2.  
  3. <Heading>Equitable drops claim against former directors</Heading>
  4.  
  5. <Date>02/12/2005</Date>
  6.  
  7. <Contents>
  8. <news story goes in here>
  9. </Contents>
  10.  
  11. <Categories>
  12. <Category ID="430009725">Finance</Category>
  13. <Category ID="430009734">Economy</Category>
  14. <Category ID="430009735">Business</Category>
  15. <Category ID="438000159">Insurance</Category>
  16. </Categories>
  17.  
  18. </Article>


So basically I need a script that can check the XML for certain stories and store them in a database. I already have the script (see below) that takes ALL the news stories from the XML file and puts them in a database. So how can I get the script to check if a story is, say a Finance story and continue to store it in a database? Would I use an if else statment? if so, where should I put it?

RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1.  
  2. Dim XMLDom
  3. Dim ItemID
  4. Dim DbConn
  5. Dim SQLString
  6. Dim ANArticleNode
  7. Dim CollectionOfArticleNodes
  8. Dim cst
  9.  
  10. Set XMLDom = CreateObject("MSXML2.DomDocument.4.0")
  11. XMLDom.async = False
  12. XMLDom.setProperty "ServerHTTPRequest", True
  13.  
  14. Set DbConn = Createobject("adodb.connection")
  15. 'DbConn.open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=pokernewsxml; OPTION=3"
  16. DbConn.open "Driver={MySQL ODBC 3.51 Driver};" & _
  17. "Server=82.195.128.88;" & _
  18. "Database=johnfog_xml;" & _
  19. "Uid=johnfog_xml;" & _
  20. "Pwd=wordword;"
  21.  
  22.  
  23. '-- Load the XML data from your live URL
  24. XMLDom.Load("http://feeds.directnews.org.uk/?ad96035d-f9fe-4a3f-a5b2-ad546b2ed850")
  25.  
  26. '-- Create a reference to a collection of all Article Tags within the downloaded XML Document
  27. Set CollectionOfArticleNodes = XMLDom.SelectNodes("InfoStreamResults/Article")
  28.  
  29. '-- Iterate the collection of Article Tags
  30. For Each ANArticleNode in CollectionOfArticleNodes
  31. ItemID = ANArticleNode.SelectSingleNode("@ID").text
  32. Heading = ANArticleNode.SelectSingleNode("Heading").text
  33. Contents = ANArticleNode.SelectSingleNode("Contents").text
  34. sDate = ANArticleNode.SelectSingleNode("Date").text
  35.  
  36. '-- Delete the item from the local database if it exists
  37.  
  38. SQLString = "DELETE FROM DeHavillandNews WHERE trim(ItemID)='" & trim(ItemID) & "';"
  39. DbConn.Execute(SQLString)
  40.  
  41. '-- Insert the item into the local database
  42. SQLString = "INSERT INTO DeHavillandNews (ItemID,Heading,Contents,strDate) " _
  43. & "VALUES('" & ItemID & "','" & EncodeIt(Heading) & "','" & EncodeIt(Contents) & "', '" & sDate & "');"
  44. DbConn.Execute(SQLString)
  45.  
  46. Next
  47.  
  48.  
  49.  
  50. '-- Handles quotations in text
  51. Function EncodeIt(TextString)
  52. TextString = Replace(CStr(TextString), "''", "'")
  53. TextString = Replace(TextString, "'", "''")
  54. EncodeIt = TextString
  55. End Function

Any help would be greatly appreciated as I am seriously stuck with this one.

Thanks folks

J
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fogofogo is offline Offline
8 posts
since Dec 2005
Dec 5th, 2005
0

Re: selecting certain xml elements

problem solved

If anyone is interested, here is the solution:

RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. Dim XMLDom
  2. Dim ItemID
  3. Dim DbConn
  4. Dim SQLString
  5. Dim ANArticleNode
  6. Dim ANArticleNode2
  7. Dim CollectionOfArticleNodes
  8. Dim CollectionOfArticleNodes2
  9. Dim cst
  10.  
  11. Set XMLDom = CreateObject("MSXML2.DomDocument.4.0")
  12. XMLDom.async = False
  13. XMLDom.setProperty "ServerHTTPRequest", True
  14.  
  15. Set DbConn = Createobject("adodb.connection")
  16. DbConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=test1.mdb"
  17.  
  18. '-- Load the XML data from your live URL
  19. XMLDom.Load("http://feeds.directnews.org.uk/?ad96035d-f9fe-4a3f-a5b2-ad546b2ed850")
  20.  
  21. '-- Create a reference to a collection of all Article Tags within the downloaded XML Document
  22. Set CollectionOfArticleNodes = XMLDom.SelectNodes("InfoStreamResults/Article")
  23.  
  24. '-- Iterate the collection of Article Tags
  25. For Each ANArticleNode in CollectionOfArticleNodes
  26. '-- Now create a reference to the category tag
  27. Set CollectionOfArticleNodes2 = ANArticleNode.SelectNodes("Categories/Category")
  28. '-- And iterate through the nodes to test for a match
  29. For Each ANArticleNode2 in CollectionOfArticleNodes2
  30. ItemID = ANArticleNode2.SelectSingleNode("@ID").text
  31. if ItemID = "430009735" then
  32. '-- Retrieve the value of the heading node from the current article
  33. Heading = ANArticleNode.SelectSingleNode("Heading").text
  34.  
  35. '-- Insert the item into the local database
  36. SQLString = "INSERT INTO test (Heading) " _
  37. & "VALUES('" & EncodeIt(Heading) & "');"
  38. DbConn.Execute(SQLString)
  39. end if
  40. Next '-- check the next category ID
  41. Next '-- move to the next article
  42.  
  43. '-- Handles quotations in text
  44. Function EncodeIt(TextString)
  45. TextString = Replace(CStr(TextString), "''", "'")
  46. TextString = Replace(TextString, "'", "''")
  47. EncodeIt = TextString
  48. End Function
  49. %>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fogofogo is offline Offline
8 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in RSS, Web Services and SOAP Forum Timeline: Before there was AJAX - there was TAXI ?
Next Thread in RSS, Web Services and SOAP Forum Timeline: Retrieve the data from the url api





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC