Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

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 December 2nd, 2005, 12:02 PM
fogofogo fogofogo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 89 fogofogo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 52 m 11 sec
Reputation Power: 5
XML issues

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.

Code:
<Article Created="16:01:59" ID="15105602">

  	<Heading>Equitable drops claim against former directors</Heading> 

  	<Date>02/12/2005</Date> 

 	<Contents>
 		<news story goes in here> 
  	</Contents>

 	<Categories>
  		<Category ID="430009725">Finance</Category> 
 		<Category ID="430009734">Economy</Category> 
 		<Category ID="430009735">Business</Category> 
  		<Category ID="438000159">Insurance</Category> 
 	</Categories>

</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?

Code:

Dim XMLDom
Dim ItemID
Dim DbConn
Dim SQLString
Dim ANArticleNode
Dim CollectionOfArticleNodes
Dim cst

Set XMLDom = CreateObject("MSXML2.DomDocument.4.0")
XMLDom.async = False
XMLDom.setProperty "ServerHTTPRequest", True

Set DbConn = Createobject("adodb.connection")
'DbConn.open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=pokernewsxml; OPTION=3"
DbConn.open "Driver={MySQL ODBC 3.51 Driver};" & _ 
        "Server=82.195.128.88;" & _ 
        "Database=johnfog_xml;" & _ 
        "Uid=johnfog_xml;" & _ 
        "Pwd=wordword;"


'-- Load the XML data from your live URL
XMLDom.Load("http://feeds.directnews.org.uk/?ad96035d-f9fe-4a3f-a5b2-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 
	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 DeHavillandNews WHERE trim(ItemID)='" & trim(ItemID) & "';"
    DbConn.Execute(SQLString)
	
	'-- Insert the item into the local database
	SQLString = "INSERT INTO DeHavillandNews (ItemID,Heading,Contents,strDate) " _
		  & "VALUES('" & ItemID & "','" & EncodeIt(Heading) & "','" & EncodeIt(Contents) & "', '" & sDate & "');" 
	DbConn.Execute(SQLString)	
	
Next



'-- Handles quotations in text
Function EncodeIt(TextString)
	TextString = Replace(CStr(TextString), "''", "'")
	TextString = Replace(TextString, "'", "''")
	EncodeIt = TextString
End Function


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

Thanks folks

J

Reply With Quote
  #2  
Old December 12th, 2005, 10:34 PM
Herong Herong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 9 Herong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 4 m 12 sec
Reputation Power: 0
Hi J,

Looks like you need another "loop" and "if". Here is what I am thinking:

Code:
...
'-- 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 DeHavillandNews WHERE trim(ItemID)='" & trim(ItemID) & "';"
    DbConn.Execute(SQLString)

' Find out if this article is related to Finance 

Set CategoryList = ANArticleNode.SelectNode("Category")
bIsFinance = False
For Each Category in CategoryList 
   bIsFinance = Category.SelectSingleNode("@ID").text = '430009725'
Next

If bIsFinance Then 

	'-- Insert the item into the local database
	SQLString = "INSERT INTO DeHavillandNews (ItemID,Heading,Contents,strDate) " _
		  & "VALUES('" & ItemID & "','" & EncodeIt(Heading) & "','" & EncodeIt(Contents) & "', '" & sDate & "');" 
	DbConn.Execute(SQLString)

End If	
	
Next


Herong

Reply With Quote
  #3  
Old December 13th, 2005, 04:36 AM
fogofogo fogofogo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 89 fogofogo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 52 m 11 sec
Reputation Power: 5
THanks for that!

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > XML issues


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