How to extract data from an XML url to Visual Studio labels [closed]

0

[! [Detail of the question] [1]] [1]

I want to do a search button by ISBN code using Virtual Studio 2013, in which it would return data from the ISBNDB.com site in XML format, which would be inserted directly into the corresponding labels , but I can not seem to get it . How can I proceed?

[UPDATE]

I was able to get the XML data as follows; First installed for the data manipulation was installed the package NuGet "CHilkatDotNet4", below, the code to obtain the data:

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 search data made by the ISBN and plays them straight to the text box exactly as he wanted, in case he does not find it, a msg appears saying "Book Not Found".

Therearestillsomeerrors,forexample,ifsomefieldisfilledmanuallyandthenputtosearch,ithasanerror.ButI'mstillanalyzing.

Wellmydoubtnowis,howdoIpickitupatthislink link ? First of all, I tried to use the above code but I think it only works in XML and apparently this link is another format, so how to proceed ..?

    
asked by anonymous 13.11.2015 / 01:54

2 answers

1

Ideally, you should give an example of what you are trying to do and not just say " I can not do it. "

But come on, the way 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 pick up the values of the first "child" element of BookList and apparently this node can have multiple BookData elements.

You can get the value of all these elements by iterating the BookList node

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
}
    
13.11.2015 / 13:30
0

You can try to get what's 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>")
    
13.11.2015 / 20:44