How to extract data from an XML url for Visual Studio Labels

Asked

Viewed 342 times

0

[![Details of the question][1][1]

I want to make a search button for the ISBN code using Virtual Studio 2013, in which he would return me data from the site ISBNDB.com in XML format, which would be inserted directly into us labels correspondents, but I’m not getting it. How can I proceed?

[UPDATING]

I was able to get the XML data as follows; 1º installed for data handling was installed the Nuget package "Chilkatdotnet4", then the code for data retrieval:

Private Sub ISBN_btn_Click(sender As Object, e As EventArgs) Handles ISBN_btn.Click
    Dim xml0 As New Chilkat.Xml()

    '  The Chilkat XML component/class is freeware.'

    Dim xml As Chilkat.Xml
    xml = xml0.HttpGet("http://isbndb.com/api/books.xml?access_key=SUA_CHAVE_DE_ACESSO=isbn&value1=" + ISBN10_txtbox.Text)
    If (xml Is Nothing) Then
        MsgBox("Livro não encontrado")
        Exit Sub
    End If

    '  First, navigate to the BookData node:'
    xml.FirstChild2()
    xml.FirstChild2()        

    '  Show the Title and AuthorsText: '
    ISBN13_txtbox.Text = ISBN13_txtbox.Text & xml.GetAttrValue("isbn13") & vbCrLf
    ISBN13_txtbox.Refresh()
    Titulo_txtbox.Text = Titulo_txtbox.Text & xml.GetChildContent("Title") & vbCrLf
    Titulo_txtbox.Refresh()
    TituloLong_txtbox.Text = TituloLong_txtbox.Text & xml.GetChildContent("TitleLong") & vbCrLf
    TituloLong_txtbox.Refresh()
    Autor_txtbox.Text = Autor_txtbox.Text & xml.GetChildContent("AuthorsText") & vbCrLf
    Autor_txtbox.Refresh()

    '  Show the publisher_id attribute of the PublisherText node:'
    Dim xml2 As Chilkat.Xml

    xml2 = xml.FindChild("PublisherText")
    Editora_txtbox.Text = Editora_txtbox.Text & xml2.GetAttrValue("publisher_id")



    '  Save the XML to a file:'
    xml.SaveXml("book.xml")
End Sub

With this he brings me the data of the search made by ISBN and plays them straight to the text box exactly as he wanted, if not find, an msg appears saying "Book Not Found". inserir a descrição da imagem aqui

It still has some errors, for example, if some field is manually filled and then put to be done the search, it presents an error. But I’m still analyzing.

Well my doubt now is, how to catch that appear on this link https://www.googleapis.com/books/v1/volumes?q=isbn+8525034304 ? First of all, I tried to use the code above but I think it only works in XML and apparently, this link is another format, so how to proceed..?

  • 5

    User posted a question, after solving edited the question to put another question.

  • Good morning @jbueno I see no problem, as long as I haven’t received any answers yet. What he needs is to organize the question, this horrible read :)

  • Good morning @Guilhermenascimento, but the question has two answers that address only the first problem...

  • 1

    @jbueno Vixe I had not seen that there were answers, sorry, really does not seem to be correct, maybe a rollback just to the first problem and guide the AP to explain the problem better and/or ask a new question :)

  • @Guilhermenascimento I think it’s a really good idea (:

  • This other format in the googleapis link is [tag:json], @Everton

  • 1

    @jbueno, that is, needs a little curating here, the section seems very messy... I’m not sure if the votes to close are correct... check out: http://meta.pt.stackoverflow.com/questions/1682/o-que-fazer-quando-o-o-p-muda-sua-question/1684#1684

  • I hadn’t come across such a situation before, so I didn’t know what to do. Thanks @brasofilo

  • 2

    @jbueno, chameleons and vampires are not simply mythical creatures of the Meta :)

  • Hello, sorry guys, I did not know q could change the question so out of the blue... Actually I wanted to have left the original question as it was, but I am not allowed to put more than 2 links :(

  • @brasofilo thanks. In this case I should put a new question telling you how to extract the json data for an Aplication form.... right?

Show 6 more comments

2 answers

1

The ideal would be for you to give an example of how you’re trying to do it and not just say, "I’m not getting through."

But come on, the path of the stones is this:

Import the namespace System.Xml.Linq - Working with Linq is much simpler in this case

using System.Xml.Linq;

var doc = XDocument.Load("caminhoDoArquivo.xml");
var titulo = doc.Descendants("Title").First().Value; //Pega o valor do primeiro elemento "Title"

Note that the above example will take the values of the first "child element" of Booklist and apparently this knot can have several elements Bookdata.

You can take the value of all these elements by iterating the node Booklist

var bookList = doc.Descendants("BookList");

foreach(var bookData in bookList)
{
    var titulo = bookData.Descendants("Title").First().Value;
    // Aqui será necessário jogar os valores numa lista ou algo semelhante
}
  • Well, I’m sorry about the way I put the question, I didn’t really know where to begin, I had tried some methods before, but I forgot to put it here..

0

You can try to get what is between two tags with this method:

Public Shared Function GetBetween(IStringStr As String, IBefore As String, IPast As String)
   On Error Resume Next
   Dim iString As String
   iString = IStringStr
   iString = Right(iString, Len(iString) - InStr(iString, IBefore) - Len(IBefore) + 1)
   iString = Mid(iString, 1, InStr(iString, IPast) - 1)
   GetBetween = iString
End Function

To use, use this code; as an example:

LabelTitulo.Text = GetBetweem(ArquivoXML.ToString(), "<Title>", "</Title>")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.