XML displays in console but not in text boxes

  • Thread starter Thread starter John Meyer
  • Start date Start date
J

John Meyer

The console code is working just fine, but it isn't putting in the text
boxes.

P.S I'm using a while loop, but I'm only expecting one answer but I
haven't found a good way to process one record.

Private Sub btnFindByISBN_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnFindByISBN.Click
Dim strSearchString As String

strSearchString = "http://isbndb.com/api/books.xml?access_key="
& "CYGCL3GT" & "&index1=isbn&value1=" & Me.txtISBN.Text



Dim reader As XmlTextReader = New XmlTextReader(strSearchString)
Do While (reader.Read())
Console.WriteLine(reader.Name)
Console.WriteLine(reader.Value)

Select Case reader.Name
Case "Title"
Me.txtTitle.Text = reader.Value
Case "AuthorsText"
Me.txtAuthors.Text = reader.Value
End Select
Loop




End Sub

Visual Basic.NET 2008
 
John said:
The console code is working just fine, but it isn't putting in the text
boxes.

P.S I'm using a while loop, but I'm only expecting one answer but I
haven't found a good way to process one record.

Private Sub btnFindByISBN_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnFindByISBN.Click
Dim strSearchString As String

strSearchString = "http://isbndb.com/api/books.xml?access_key="
& "CYGCL3GT" & "&index1=isbn&value1=" & Me.txtISBN.Text



Dim reader As XmlTextReader = New XmlTextReader(strSearchString)
Do While (reader.Read())
Console.WriteLine(reader.Name)
Console.WriteLine(reader.Value)

Select Case reader.Name
Case "Title"
Me.txtTitle.Text = reader.Value
Case "AuthorsText"
Me.txtAuthors.Text = reader.Value
End Select
Loop




End Sub

Visual Basic.NET 2008

With VB.NET 2008 you could use LINQ to XML instead of Xml(Text)Reader,
see MSDN online or your local copy:
http://msdn.microsoft.com/en-us/library/bb387098.aspx

As for your code above, with the XmlReader API you can use code like this:
Using reader As XmlReader = XmlReader.Create(strSearchString)
While reader.Read()
If reader.NodeType = XmlNodeType.Element And reader.Name =
"Title" Then
Me.txtTitle.Text = reader.ReadString()
Else if reader.NodeType = XmlNodeType.Element And reader.Name =
"AuthorsText" Then
Me.txtAuthors.Text = reader.ReadString()
End If
End While
End Using

If that does not help then show us how a sample of the XML looks.
 
Rack, that worked! Thanks



Martin said:
With VB.NET 2008 you could use LINQ to XML instead of Xml(Text)Reader,
see MSDN online or your local copy:
http://msdn.microsoft.com/en-us/library/bb387098.aspx

As for your code above, with the XmlReader API you can use code like this:
Using reader As XmlReader = XmlReader.Create(strSearchString)
While reader.Read()
If reader.NodeType = XmlNodeType.Element And reader.Name = "Title"
Then
Me.txtTitle.Text = reader.ReadString()
Else if reader.NodeType = XmlNodeType.Element And reader.Name =
"AuthorsText" Then
Me.txtAuthors.Text = reader.ReadString()
End If
End While
End Using

If that does not help then show us how a sample of the XML looks.
 
Yeah, I originally posted this in m.p.vb.general.discussion but somebody
said that I was talking Visual Basic.NET, not real Visual Basic. Go fig.
 
Back
Top