XML displays in console but not in text boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Meyer

    XML displays in console but not in text boxes

    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_C lick(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles btnFindByISBN.C lick
    Dim strSearchString As String

    strSearchString = "http://isbndb.com/api/books.xml?acces s_key="
    & "CYGCL3GT" & "&index1=isbn&v alue1=" & Me.txtISBN.Text



    Dim reader As XmlTextReader = New XmlTextReader(s trSearchString)
    Do While (reader.Read())
    Console.WriteLi ne(reader.Name)
    Console.WriteLi ne(reader.Value )

    Select Case reader.Name
    Case "Title"
    Me.txtTitle.Tex t = reader.Value
    Case "AuthorsTex t"
    Me.txtAuthors.T ext = reader.Value
    End Select
    Loop




    End Sub

    Visual Basic.NET 2008
  • Martin Honnen

    #2
    Re: XML displays in console but not in text boxes

    John Meyer wrote:
    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_C lick(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles btnFindByISBN.C lick
    Dim strSearchString As String
    >
    strSearchString = "http://isbndb.com/api/books.xml?acces s_key="
    & "CYGCL3GT" & "&index1=isbn&v alue1=" & Me.txtISBN.Text
    >
    >
    >
    Dim reader As XmlTextReader = New XmlTextReader(s trSearchString)
    Do While (reader.Read())
    Console.WriteLi ne(reader.Name)
    Console.WriteLi ne(reader.Value )
    >
    Select Case reader.Name
    Case "Title"
    Me.txtTitle.Tex t = reader.Value
    Case "AuthorsTex t"
    Me.txtAuthors.T ext = 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:


    As for your code above, with the XmlReader API you can use code like this:
    Using reader As XmlReader = XmlReader.Creat e(strSearchStri ng)
    While reader.Read()
    If reader.NodeType = XmlNodeType.Ele ment And reader.Name =
    "Title" Then
    Me.txtTitle.Tex t = reader.ReadStri ng()
    Else if reader.NodeType = XmlNodeType.Ele ment And reader.Name =
    "AuthorsTex t" Then
    Me.txtAuthors.T ext = reader.ReadStri ng()
    End If
    End While
    End Using

    If that does not help then show us how a sample of the XML looks.
    --

    Martin Honnen --- MVP XML

    Comment

    • John Meyer

      #3
      Re: XML displays in console but not in text boxes

      Rack, that worked! Thanks



      Martin Honnen wrote:
      John Meyer wrote:
      >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_C lick(ByVal sender As System.Object, ByVal e
      >As System.EventArg s) Handles btnFindByISBN.C lick
      > Dim strSearchString As String
      >>
      > strSearchString = "http://isbndb.com/api/books.xml?acces s_key="
      >& "CYGCL3GT" & "&index1=isbn&v alue1=" & Me.txtISBN.Text
      >>
      >>
      >>
      > Dim reader As XmlTextReader = New XmlTextReader(s trSearchString)
      > Do While (reader.Read())
      > Console.WriteLi ne(reader.Name)
      > Console.WriteLi ne(reader.Value )
      >>
      > Select Case reader.Name
      > Case "Title"
      > Me.txtTitle.Tex t = reader.Value
      > Case "AuthorsTex t"
      > Me.txtAuthors.T ext = 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:

      >
      As for your code above, with the XmlReader API you can use code like this:
      Using reader As XmlReader = XmlReader.Creat e(strSearchStri ng)
      While reader.Read()
      If reader.NodeType = XmlNodeType.Ele ment And reader.Name = "Title"
      Then
      Me.txtTitle.Tex t = reader.ReadStri ng()
      Else if reader.NodeType = XmlNodeType.Ele ment And reader.Name =
      "AuthorsTex t" Then
      Me.txtAuthors.T ext = reader.ReadStri ng()
      End If
      End While
      End Using
      >
      If that does not help then show us how a sample of the XML looks.

      Comment

      • John Meyer

        #4
        Re: XML displays in console but not in text boxes

        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.
        Martin Honnen wrote:
        John Meyer wrote:
        >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_C lick(ByVal sender As System.Object, ByVal e
        >As System.EventArg s) Handles btnFindByISBN.C lick
        > Dim strSearchString As String
        >>
        > strSearchString = "http://isbndb.com/api/books.xml?acces s_key="
        >& "CYGCL3GT" & "&index1=isbn&v alue1=" & Me.txtISBN.Text
        >>
        >>
        >>
        > Dim reader As XmlTextReader = New XmlTextReader(s trSearchString)
        > Do While (reader.Read())
        > Console.WriteLi ne(reader.Name)
        > Console.WriteLi ne(reader.Value )
        >>
        > Select Case reader.Name
        > Case "Title"
        > Me.txtTitle.Tex t = reader.Value
        > Case "AuthorsTex t"
        > Me.txtAuthors.T ext = 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:

        >
        As for your code above, with the XmlReader API you can use code like this:
        Using reader As XmlReader = XmlReader.Creat e(strSearchStri ng)
        While reader.Read()
        If reader.NodeType = XmlNodeType.Ele ment And reader.Name = "Title"
        Then
        Me.txtTitle.Tex t = reader.ReadStri ng()
        Else if reader.NodeType = XmlNodeType.Ele ment And reader.Name =
        "AuthorsTex t" Then
        Me.txtAuthors.T ext = reader.ReadStri ng()
        End If
        End While
        End Using
        >
        If that does not help then show us how a sample of the XML looks.

        Comment

        Working...