Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling XML Into Database

Status
Not open for further replies.

Ddraig

MIS
Jul 16, 2004
97
US
Howdy,

I'm having a slight issue with my code here and I'm not exactly sure I've got it right. Basically what I'm trying to do is to pull in URLs (strAddress) from a database, then have it send that to my code the parses the XML. Then it should go to the next one, and do the same thing etc. Eventually I'd like for it to add the feeds to the database/cache them, but my biggest issue right now is trying to get it to loop through GrabAddress() and display the right feed URLs.

Pasted my code below:

Public Sub GrabAddress()
For i As Integer = 0 To DataSet11.Tables(0).Rows.Count - 1
MessageBox.Show(DataSet11.Tables(0).Rows.Count & " " & i)
Dim dr As DataRow = DataSet11.Tables(0).Rows(i)
i = i + 1
strAddress = dr("AddRemove_Feed_URL")
MessageBox.Show(strAddress)
GetFeedData(strAddress)
MessageBox.Show(DataSet11.Tables(0).Rows.Count & " " & i)
Next

End Sub


'Import Feed and Parse into Database
Public Sub GetFeedData(ByVal sender As String)

'Dim address As String = cmbFeedSelect.Text
xDoc = New MSXML.DOMDocument

xDoc.async = False
'xDoc.validateOnParse = False

If xDoc.load(strAddress) Then
'Reads the XML Document and all of the Nodes
Nodes = xDoc.documentElement.getElementsByTagName("item")
Dim i As Integer
For i = 0 To Nodes.length - 1
xNode = Nodes.item(i)
Try



MessageBox.Show(xNode.selectSingleNode("link").text)
MessageBox.Show(xNode.selectSingleNode("pubDate").text)
MessageBox.Show(xNode.selectSingleNode("title").text)
MessageBox.Show(xNode.selectSingleNode("description").text)
'Dim drw As DataRow
'drw = DataSet21.Tables(0).NewRow
'drw.Item("Feed_Article_" & i + 1 & "_Link") = Trim(xNode.selectSingleNode("link").text)
'drw.Item("Feed_Article_" & i + 1 & "_PubDate") = Trim(xNode.selectSingleNode("pubDate").text)
'drw.Item("Feed_Article_" & i + 1 & "_Title") = Trim(xNode.selectSingleNode("title").text)
'drw.Item("Feed_Article_" & i + 1 & "_Description") = Trim(xNode.selectSingleNode("link").text)
'DataSet21.Tables(0).Rows.Add(drw)
'OleDbDataAdapter1.Update(DataSet21)
'TitleSelect.SetValue(xNode.selectSingleNode("description").text, i)
'URLSelect.SetValue(xNode.selectSingleNode("link").text, i)
'PubDateSelect.SetValue(xNode.selectSingleNode("pubDate").text, i)
'lstTitle.Items.Add(xNode.selectSingleNode("pubDate").text & ": " & xNode.selectSingleNode("title").text)
'lstTitle.ValueMember = xNode.selectSingleNode("link").text
'lstTitle.SelectedIndex = 0
Catch ex As Exception

End Try
'OLD Code

''Dim iteminfo As String
'Try



' 'iteminfo = "Title: " & xNode.selectSingleNode("title").text & vbCrLf & _
' '"Link: " & xNode.selectSingleNode("link").text & vbCrLf & _
' '"Description: " & xNode.selectSingleNode("description").text & vbCrLf & _
' '"PubDate: " & xNode.selectSingleNode("pubDate").text & vbCrLf
' ''"Catagory: " & xNode.selectSingleNode("catagory").text & vbCrLf

' 'MsgBox(iteminfo, vbExclamation)
' 'Label1.Text = xNode.selectSingleNode("title").text
' 'TextBox1.Text = xNode.selectSingleNode("link").text
'Catch ex As Exception

'End Try
Next

Else
Dim strErrText As String
Dim xPE As MSXML.IXMLDOMParseError
' Obtain the ParseError object
xPE = xDoc.parseError
With xPE
strErrText = "Your XML Document failed to load" & _
"due the following error." & vbCrLf & _
"Error #: " & .errorCode & ": " & xPE.reason & _
"Line #: " & .line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .url
End With

MsgBox(strErrText, vbExclamation)
xPE = Nothing
End If
End Sub
 
Why are you incrementing i inside the For loop?

Public Sub GrabAddress()
For i As Integer = 0 To DataSet11.Tables(0).Rows.Count - 1
MessageBox.Show(DataSet11.Tables(0).Rows.Count & " " & i)
Dim dr As DataRow = DataSet11.Tables(0).Rows(i)
[red]i = i + 1[/red]
strAddress = dr("AddRemove_Feed_URL")
MessageBox.Show(strAddress)
GetFeedData(strAddress)
MessageBox.Show(DataSet11.Tables(0).Rows.Count & " " & i)
Next

End Sub

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Its ok...I was working on some SQL code the other day...banging my head against the monitor for hours trying to get the data I wanted. Finally, I realized that all I had to do was change an inner join to a left join, and all was well.

Its usually the small things. :)


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Now to figure out why it isn't updating the database :p
 
Assuming you have an XML file, and a table in a database with the same structure. You can use dataset.readXML(filename) to get the xml data. Then open another datatable for the database table. Then loop through all of the rows in the XML data table and use the database's datatable.importrow to pull them over:
Code:
dim dtTableName as datatable 'the data table that is connected to the database's table

dim dsXML as new dataset
dsXML.readXML(MyFileName)

for each dr as datarow in dsXML.tables(0).rows
  dtTableName.importrow(dr)
next

-Rick


VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top