Consuming data from a webservice in xml with vb.net

0

I'm making a website on vb.net that consumes a webservice that uses Example , which returns me all countries.

I only have one Send button that calls the countries and I have an LBL that shows me the result.

   
Imports service_country = WebServiceVB2.country

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim serv_country As New service_country.country '--Creo el objeto del servicio'
        Dim MyDoc As New System.Xml.XmlDocument
        Dim MyXml As String = serv_country.GetCountries() '--Ejecuto el procedimiento del webservice y lo guardo en string'

        MyDoc.LoadXml(MyXml) '--Leo el contenido del Myxml y lo convierto en XML'
        Dim SymbolText As String = MyDoc.SelectSingleNode("//NewDataSet/Table/Name").InnerText '--Selecciono unicamente el nodo en donde este Name'
        Label1.Text = SymbolText

    End Sub

The question is: How can I go through all the xml values? Since currently only returns one. I show the example:

Thanks in advance for your response.

    
asked by cport93 16.05.2017 в 00:34
source

1 answer

0

Because the XML document has symbols like "& g;" Use the following procedure:

Dim doc1 As XDocument = XDocument.Load(URL)

Dim docStr As String = doc1.ToString()
docStr = docStr.Replace(">", ">")
docStr = docStr.Replace("&lt;", "<")

Dim doc2 As XDocument = XDocument.Parse(docStr)

Dim root As XElement = doc2.Root
Dim defaultNs As XNamespace = root.GetDefaultNamespace()
Dim names() As String = doc2.Descendants(defaultNs + "Name").Select(Function(x) CType(x, String)).ToArray()
For Each nombres In names
  Label1.Text = Label1.Text & nombres
Next

More information on the answer

    
answered by 16.05.2017 в 16:30