473,473 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Refreshing the data in an XMLReader object

I'm writing a stock ticker for a stock market simulation, and can load the
data into the xmlreader in the first place, but can't figure out how to
refresh/update the data in it. Any ideas?

Code:
Public Class Form1

Inherits System.Windows.Forms.Form

'Dataset used to read data in from files

Dim dsTicker As New DataSet("Ticker")

'XML Reader used to read data from dataset and

'handle it

Dim xmlReader As New Xml.XmlDataDocument()

'Path to xml file

Const strTickerPath = "http://www.vastock.com/raw/ticker.xml"

'String used to hold xml read from file, to pass to the xml reader

Dim strCurrentXML As String

'Strings used to hold information about the stock

Dim strCurrentStockName As String

Dim strCurrentStockPrice As String

Dim strCurrentStockChange As String

'Integer used to loop through records

Dim intCurrentRow As Integer = 0

Dim intCurrentLoop

Dim intTickerSpeed As Integer = 100

Dim strTickerText As String

Dim strWatchListOn As Boolean

Dim strWatchList As String

Dim strWatchListData As String

Dim i As Long

Dim WatchArray As Array

[Snipped autogen form designer code]

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Show loading window

Dim LoadingForm As New Loading()

LoadingForm.Show()

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

'Refresh Ticker

LoadTickerData()

InsertTickerData()

'Set size

Me.Width = Screen.FromControl(Me).GetWorkingArea(Me).Width

tmrScroll.Interval = intTickerSpeed

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

Dim temp As New Form()

MaintainSize(temp)

LoadingForm.Close()

End Sub

Private Sub InsertTickerData()

strWatchList = ""

For intCurrentLoop = 1 To
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes.C ount - 1

'Load data into strings, using indices to navigate - 0 being the first node
meaning:

'xmlReader.ChildNodes(0) is navigating to the <ticker> element

'xmlReader.ChildNodes(0).ChildNodes(1) is navigating to the <data> element

'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes( 0) is navigating to the
<entry> element

'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes( 0).ChildNodes(n) is
navigating to:

'0 = Stock Name

'1 = Stock Price

'2 = Stock Price Change

'Then .InnerText simply reads the data from that node.

strCurrentStockName =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(0
).InnerText

strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(1
).InnerText

strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(2
).InnerText

If strWatchListOn = "1" Then

For i = 0 To WatchArray.GetUpperBound(0)

If strCurrentStockName = WatchArray(i) Then

strWatchList &= strCurrentStockName

strWatchList &= " Price: v$" & strCurrentStockPrice

strWatchList &= " Change: v$"

strWatchList &= " | "

End If

Next

End If

lblTicker.Text &= strCurrentStockName

lblTicker.Text &= " Price: v$" & strCurrentStockPrice

lblTicker.Text &= " Change: " & strCurrentStockChange

lblTicker.Text &= " | "

intCurrentRow = intCurrentRow + 1

Next

strTickerText = lblTicker.Text

End Sub

Private Sub LoadTickerData()

'Read the xml file into the dataset

dsTicker.ReadXml(strTickerPath)

'Set the string to the ACTUAL XML - not the data

strCurrentXML = dsTicker.GetXml

'Load that string/xml into the xmlReader for handling

xmlReader.LoadXml(strCurrentXML)

End Sub

I'll attach the full code in a message below this one.
Nov 20 '05 #1
1 2292
Public Class Form1

Inherits System.Windows.Forms.Form

'Dataset used to read data in from files

Dim dsTicker As New DataSet("Ticker")

'XML Reader used to read data from dataset and

'handle it

Dim xmlReader As New Xml.XmlDataDocument()

'Path to xml file

Const strTickerPath = "http://www.vastock.com/raw/ticker.xml"

'String used to hold xml read from file, to pass to the xml reader

Dim strCurrentXML As String

'Strings used to hold information about the stock

Dim strCurrentStockName As String

Dim strCurrentStockPrice As String

Dim strCurrentStockChange As String

'Integer used to loop through records

Dim intCurrentRow As Integer = 0

Dim intCurrentLoop

Dim intTickerSpeed As Integer = 100

Dim strTickerText As String

Dim strWatchListOn As Boolean

Dim strWatchList As String

Dim strWatchListData As String

Dim i As Long

Dim WatchArray As Array

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents mnuMain As System.Windows.Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem

Friend WithEvents tmrScroll As System.Windows.Forms.Timer

Friend WithEvents lblTicker As System.Windows.Forms.RichTextBox

Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Me.mnuMain = New System.Windows.Forms.MainMenu()

Me.MenuItem1 = New System.Windows.Forms.MenuItem()

Me.MenuItem4 = New System.Windows.Forms.MenuItem()

Me.MenuItem5 = New System.Windows.Forms.MenuItem()

Me.MenuItem7 = New System.Windows.Forms.MenuItem()

Me.MenuItem2 = New System.Windows.Forms.MenuItem()

Me.tmrScroll = New System.Windows.Forms.Timer(Me.components)

Me.lblTicker = New System.Windows.Forms.RichTextBox()

Me.MenuItem3 = New System.Windows.Forms.MenuItem()

Me.SuspendLayout()

'

'mnuMain

'

Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1, Me.MenuItem5})

'

'MenuItem1

'

Me.MenuItem1.Index = 0

Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem4})

Me.MenuItem1.Text = "&File"

'

'MenuItem4

'

Me.MenuItem4.Index = 0

Me.MenuItem4.Text = "Exit"

'

'MenuItem5

'

Me.MenuItem5.Index = 1

Me.MenuItem5.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem7, Me.MenuItem2, Me.MenuItem3})

Me.MenuItem5.Text = "&Application"

'

'MenuItem7

'

Me.MenuItem7.Index = 0

Me.MenuItem7.Text = "A&bout"

'

'MenuItem2

'

Me.MenuItem2.Index = 1

Me.MenuItem2.Text = "&Configuration"

'

'tmrScroll

'

Me.tmrScroll.Enabled = True

'

'lblTicker

'

Me.lblTicker.BorderStyle = System.Windows.Forms.BorderStyle.None

Me.lblTicker.Dock = System.Windows.Forms.DockStyle.Fill

Me.lblTicker.Font = New System.Drawing.Font("Courier New", 8.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))

Me.lblTicker.Multiline = False

Me.lblTicker.Name = "lblTicker"

Me.lblTicker.ReadOnly = True

Me.lblTicker.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None

Me.lblTicker.Size = New System.Drawing.Size(824, 12)

Me.lblTicker.TabIndex = 0

Me.lblTicker.Text = ""

'

'MenuItem3

'

Me.MenuItem3.Index = 2

Me.MenuItem3.Text = "Stock &Watchlist"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(824, 12)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblTicker})

Me.ForeColor = System.Drawing.SystemColors.ControlLight

Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWind ow

Me.MaximizeBox = False

Me.Menu = Me.mnuMain

Me.MinimizeBox = False

Me.Name = "Form1"

Me.ShowInTaskbar = False

Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual

Me.Text = "Virtual Airline Stock Market - Stock Ticker"

Me.TopMost = True

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Show loading window

Dim LoadingForm As New Loading()

LoadingForm.Show()

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

'Refresh Ticker

LoadTickerData()

InsertTickerData()

'Set size

Me.Width = Screen.FromControl(Me).GetWorkingArea(Me).Width

tmrScroll.Interval = intTickerSpeed

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

Dim temp As New Form()

MaintainSize(temp)

LoadingForm.Close()

End Sub

Private Sub InsertTickerData()

strWatchList = ""

For intCurrentLoop = 1 To
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes.C ount - 1

'Load data into strings, using indices to navigate - 0 being the first node
meaning:

'xmlReader.ChildNodes(0) is navigating to the <ticker> element

'xmlReader.ChildNodes(0).ChildNodes(1) is navigating to the <data> element

'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes( 0) is navigating to the
<entry> element

'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes( 0).ChildNodes(n) is
navigating to:

'0 = Stock Name

'1 = Stock Price

'2 = Stock Price Change

'Then .InnerText simply reads the data from that node.

strCurrentStockName =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(0
).InnerText

strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(1
).InnerText

strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(2
).InnerText

If strWatchListOn = "1" Then

For i = 0 To WatchArray.GetUpperBound(0)

If strCurrentStockName = WatchArray(i) Then

strWatchList &= strCurrentStockName

strWatchList &= " Price: v$" & strCurrentStockPrice

strWatchList &= " Change: v$"

strWatchList &= " | "

End If

Next

End If

lblTicker.Text &= strCurrentStockName

lblTicker.Text &= " Price: v$" & strCurrentStockPrice

lblTicker.Text &= " Change: " & strCurrentStockChange

lblTicker.Text &= " | "

intCurrentRow = intCurrentRow + 1

Next

strTickerText = lblTicker.Text

End Sub

Private Sub LoadTickerData()

'Read the xml file into the dataset

dsTicker.ReadXml(strTickerPath)

'Set the string to the ACTUAL XML - not the data

strCurrentXML = dsTicker.GetXml

'Load that string/xml into the xmlReader for handling

xmlReader.LoadXml(strCurrentXML)

End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem4.Click

'Exit Program

End

End Sub

Private Sub MaintainSize(ByVal frmTicker As Form)

Dim BoundRec As Rectangle = Screen.GetBounds(frmTicker)

Me.Width = BoundRec.Width

Me.Height = 64

Me.Left = 0

Me.Top = 0

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

Dim temp As New Form()

MaintainSize(temp)

End Sub

Private Sub tmrScroll_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tmrScroll.Tick

If lblTicker.Text = "" Then

lblTicker.Text = strTickerText

Else

lblTicker.Text = Mid(lblTicker.Text, 2)

End If

Dim temp As New Form()

MaintainSize(temp)

End Sub

Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem7.Click

'Load about form

Dim AboutForm As New About()

AboutForm.Show()

End Sub

Private Sub MenuItem2_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click

intTickerSpeed = InputBox("Please enter the speed for the ticker (characters
per interval):")

tmrScroll.Interval = intTickerSpeed

End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem3.Click

End Sub

End Class

"Angus Lepper" <CE*@AngusEnterprises.cjb.net> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...
I'm writing a stock ticker for a stock market simulation, and can load the
data into the xmlreader in the first place, but can't figure out how to
refresh/update the data in it. Any ideas?

Code:
Public Class Form1

Inherits System.Windows.Forms.Form

'Dataset used to read data in from files

Dim dsTicker As New DataSet("Ticker")

'XML Reader used to read data from dataset and

'handle it

Dim xmlReader As New Xml.XmlDataDocument()

'Path to xml file

Const strTickerPath = "http://www.vastock.com/raw/ticker.xml"

'String used to hold xml read from file, to pass to the xml reader

Dim strCurrentXML As String

'Strings used to hold information about the stock

Dim strCurrentStockName As String

Dim strCurrentStockPrice As String

Dim strCurrentStockChange As String

'Integer used to loop through records

Dim intCurrentRow As Integer = 0

Dim intCurrentLoop

Dim intTickerSpeed As Integer = 100

Dim strTickerText As String

Dim strWatchListOn As Boolean

Dim strWatchList As String

Dim strWatchListData As String

Dim i As Long

Dim WatchArray As Array

[Snipped autogen form designer code]

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Show loading window

Dim LoadingForm As New Loading()

LoadingForm.Show()

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

'Refresh Ticker

LoadTickerData()

InsertTickerData()

'Set size

Me.Width = Screen.FromControl(Me).GetWorkingArea(Me).Width

tmrScroll.Interval = intTickerSpeed

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

Dim temp As New Form()

MaintainSize(temp)

LoadingForm.Close()

End Sub

Private Sub InsertTickerData()

strWatchList = ""

For intCurrentLoop = 1 To
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes.C ount - 1

'Load data into strings, using indices to navigate - 0 being the first node meaning:

'xmlReader.ChildNodes(0) is navigating to the <ticker> element

'xmlReader.ChildNodes(0).ChildNodes(1) is navigating to the <data> element

'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes( 0) is navigating to the
<entry> element

'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes( 0).ChildNodes(n) is
navigating to:

'0 = Stock Name

'1 = Stock Price

'2 = Stock Price Change

'Then .InnerText simply reads the data from that node.

strCurrentStockName =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(0 ).InnerText

strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(1 ).InnerText

strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(2 ).InnerText

If strWatchListOn = "1" Then

For i = 0 To WatchArray.GetUpperBound(0)

If strCurrentStockName = WatchArray(i) Then

strWatchList &= strCurrentStockName

strWatchList &= " Price: v$" & strCurrentStockPrice

strWatchList &= " Change: v$"

strWatchList &= " | "

End If

Next

End If

lblTicker.Text &= strCurrentStockName

lblTicker.Text &= " Price: v$" & strCurrentStockPrice

lblTicker.Text &= " Change: " & strCurrentStockChange

lblTicker.Text &= " | "

intCurrentRow = intCurrentRow + 1

Next

strTickerText = lblTicker.Text

End Sub

Private Sub LoadTickerData()

'Read the xml file into the dataset

dsTicker.ReadXml(strTickerPath)

'Set the string to the ACTUAL XML - not the data

strCurrentXML = dsTicker.GetXml

'Load that string/xml into the xmlReader for handling

xmlReader.LoadXml(strCurrentXML)

End Sub

I'll attach the full code in a message below this one.

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: xmlguy | last post by:
Cant seem to solve this problem I need to be able to re-use XmlReader and XPathDocument for an XSLT Transform. Basically I have defined following interfaces: Class Render (Common and...
2
by: Dylan Phillips | last post by:
A strang error is occurring when I run the following code: SqlConnection c = new SqlConnection(); c.ConnectionString = "Initial Catalog=Northwind;user id=sa;password=kat1ie;Data Source=server";...
11
by: Ignacio X. Domínguez | last post by:
Hi. I'm developing a desktop application that needs to store some data in a local file. Let's say for example that I want to have an address book with names and phone numbers in a file. I would...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
0
by: Jen | last post by:
My main question: "How can I get a TextReader or Stream object from an existing XmlReader?". Read on for more: I have an existing XmlReader. Let's call it reader1. I'm creating another reader,...
3
by: Jeff Richardson | last post by:
This is a repost from the InfoPath news group. Hi, I am writing a SharePoint application that works with InfoPath forms. When a user submits a completed InfoPath form to a forms library my code...
2
by: jonfroehlich | last post by:
According to the MSDN documentation within the XmlTextReader class for ..NET 2.0, the recommended practice to create XmlReader instances is using the XmlReaderSettings class and the...
2
by: Rami | last post by:
I am using an XSD schema to validate an XML document. I want to validate both XML structure and . When I try to validate the document, the validation only checks for things like proper tags, and...
2
ssnaik84
by: ssnaik84 | last post by:
Hello, I have hosted a website on GoDaddy.com. It's a share hosting. I am using XML file as a database. That means, I am reading and writing data into XML file instead of regular RDBMS (MySQL, MS...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.