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

XML Parsing from a String in VB

Status
Not open for further replies.

JackBurton07

IS-IT--Management
Oct 17, 2007
75
GB
VS 2005
.NET CF

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
 
I would suggest you check the typename of the str. The error message seems to suggest it refuses to perform without casting, and/or auto casting failed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top