1

我正在尝试创建一个家庭图书馆数据库程序。我有一个条形码扫描仪,希望能够在线查找图书的 ISBN 并将书名和作者添加到 Microsoft Access 文件中。我的代码的每一部分都在工作,除了以下内容:

Public Sub XMLStuff()
For i = 0 To UBound(aryISBN) - 1
        ' If the ISBN exists
        If (aryISBN(i).Chars(1) <> "#") Then
            GETXML(i, aryISBN)
            ReadXML(Title, Author, intCount)
        Else
            MsgBox("this is not a valid isbn")
        End If
    Next

End Sub


Public Sub GETXML(ByVal i As Integer, ByVal aryISBN As String())
    Dim accessKey As String = "NUMBER"
    ' URL for isbndb.com API
    Dim url As String = ("https://isbndb.com/api/books.xml?access_key=" + accessKey + "&results=texts&index1=isbn&value1=" + aryISBN(i))
    ' Create new XML reader from URL
    Dim reader As XmlTextReader = New XmlTextReader(url)

    ' Delete XML file if it already exists
    If System.IO.File.Exists(FILE_NAME) Then
        My.Computer.FileSystem.DeleteFile(FILE_NAME)
    End If

    Dim objWriter As New System.IO.StreamWriter(FILE_NAME, False)

    ' Write entire XML output to file
    Do While (reader.Read())
        Select Case reader.NodeType
            Case XmlNodeType.Element 'Display beginning of element.
                objWriter.Write("<" + reader.Name)
                objWriter.WriteLine(">")
            Case XmlNodeType.Text 'Display the text in each element.
                objWriter.WriteLine(reader.Value)
            Case XmlNodeType.EndElement 'Display end of element.
                objWriter.Write("</" + reader.Name)
                objWriter.WriteLine(">")
        End Select
    Loop
    objWriter.Close()
    reader.Close()
End Sub

当数组中有两个有效的 ISBN 时,第一个数组总是返回完整的 XML(下面的第一个示例),但第二个 ISBN 总是返回错误的 XML(下面的第二个示例)。我已经在浏览器中直接测试了每个 ISBN,所以我知道第二次应该返回什么 XML。我的循环做错了吗?

<ISBNdb>
<BookList>
<BookData isbn="1612510248">
<Title>...</Title>
<TitleLong>...</TitleLong>
<AuthorsText>...</AuthorsText>
</BookData>
</BookList>
</ISBNdb>

<ISBNdb>
<BookList>
</BookList>
</ISBNdb>
4

0 回答 0