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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML parsing

Status
Not open for further replies.

JackBurton07

IS-IT--Management
Oct 17, 2007
75
0
0
GB
Hi everyone,

I am writing a mobile app in vb that returns stock data in xml format from a web service. This works fine but it returns it all in xml format. I want to parse the xml so that each item is on a separate line. I cant get it to work.

I would be grateful if you could have a look for me . The error that I am getting is "Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(path As String, encoding As System.Text.Encoding)': Argument matching parameter 'path' narrows from 'Object' to 'String'.
'Public Sub New(stream As System.IO.Stream, encoding As System.Text.Encoding)': Argument matching parameter 'stream' narrows from 'Object' to 'System.IO.Stream'.


Many thanks for taking the time to help,.

JB
____________________________________________________________________________
Imports System.Xml
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Net



Public Class Form1

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



End Sub

Function DownloadFeeds()
Dim xml As New XmlDocument
Dim ws As New stock.StockQuote
ws.Url = " Dim str = ws.GetQuote(TextBox1.Text)
Dim reader As StreamReader
reader = New StreamReader(str, System.Text.Encoding.UTF8)
xml.Load(reader)

Dim titleNode As XmlNode = xml.SelectSingleNode("StockQuotes/Stock/Symbol")
Dim title = titleNode.InnerText

'---select all <StockQuotes><Stock> elements---
Dim nodes As XmlNodeList = xml.SelectNodes("StockQuotes/Stock")

Dim result As String = String.Empty
For Each node As XmlNode In nodes
'select each post's <title> and <description> elements
TextBox3.Text = node.SelectSingleNode("Symbol").InnerText & Chr(3)
TextBox4.Text= node.SelectSingleNode("Last").InnerText & Chr(12)
TextBox5.Text= node.SelectSingleNode("Date").InnerText & Chr(12)
TextBox6.Text= node.SelectSingleNode("Time").InnerText & Chr(12)
TextBox7.Text= node.SelectSingleNode("Change").InnerText & Chr(12)
TextBox8.Text= node.SelectSingleNode("Open").InnerText & Chr(12)
TextBox9.Text= node.SelectSingleNode("AnnRange").InnerText & Chr(12)
TextBox10.Text= node.SelectSingleNode("Earns").InnerText & Chr(12)
TextBox11.Text= node.SelectSingleNode("P-E").InnerText & Chr(12)
TextBox12.Text= node.SelectSingleNode("Name").InnerText & Chr(12)
Next
Return

End Function

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

DownloadFeeds()

End Sub

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

End Sub
End Class
 
you have the variable that is passed to the path parameter of the StreamReader defined as an Object, not a String.

Dim str As String = ws.GetQuote(TextBox1.Text)
Dim reader As StreamReader
reader = New StreamReader(str, System.Text.Encoding.UTF8)

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

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks - Its now throwing "illegal characters in path"

 
StreamReader can only open local files. Look into System.Xml.XmlTextReader instead.



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

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Hi Thanks Again - I changed it but its still throwing out "illegal characters in path"



Imports System.Xml
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Net



Public Class Form1

Dim ws As New stock.StockQuote

Dim wsdoc As New XmlDocument
Dim wsurl As String


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



End Sub

Function DownloadFeeds()
Dim xml As New XmlDocument
Dim ws As New stock.StockQuote
ws.Url = " Dim str As String = ws.GetQuote(TextBox1.Text)

Dim reader As System.Xml.XmlTextReader
reader = New System.Xml.XmlTextReader(str)
xml.Load(reader)
Dim titleNode As XmlNode = xml.SelectSingleNode("StockQuotes/Stock/Symbol")
Dim title = titleNode.InnerText

'---select all <StockQuotes><Stock> elements---
Dim nodes As XmlNodeList = xml.SelectNodes("StockQuotes/Stock")

Dim result As String = String.Empty
For Each node As XmlNode In nodes
TextBox3.Text = node.SelectSingleNode("Symbol").InnerText '& Chr(3)
TextBox4.Text = node.SelectSingleNode("Last").InnerText '& Chr(12)
TextBox5.Text = node.SelectSingleNode("Date").InnerText '& Chr(12)
TextBox6.Text = node.SelectSingleNode("Time").InnerText '& Chr(12)
TextBox7.Text = node.SelectSingleNode("Change").InnerText '& Chr(12)
TextBox8.Text = node.SelectSingleNode("Open").InnerText '& Chr(12)
TextBox9.Text = node.SelectSingleNode("AnnRange").InnerText '& Chr(12)
TextBox10.Text = node.SelectSingleNode("Earns").InnerText '& Chr(12)
'TextBox11.Text = node.SelectSingleNode("P-E").InnerText '& Chr(12)
TextBox12.Text = node.SelectSingleNode("Name").InnerText '& Chr(12)
Next
Return MessageBox.Show(" Success")

End Function



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DownloadFeeds()
End Sub
End Class
 
What does this function do?

ws.GetQuote(TextBox1.Text)



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

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
It uses the webservice "getquote" using a stock symbol that the user enters into textbox1.text

e.g the user enters "GS" into the textbox, clicks submit and all the stock data is pulled from the web service
 
Hi Jack,

As far as I can see your problem lies in your approach in getting your data, as this is a Web Service the data will be encapsulated in a SOAP Envelope, so won't you need to process this first?





woogoo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top