Author Topic: HTTPS request and read XML  (Read 1418 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 241
HTTPS request and read XML
« on: October 31, 2020, 07:55:39 AM »
How to do in VB.NET execute the following request and then obtain the elevation value in the returned XML?

"https://maps.googleapis.com/maps/api/elevation/xml?locations=-3.60,-45.35&key=AIzaSyCnQ2jPnu0bhyDwJ8vMq5u4untaiEu5ma4"

<ElevationResponse>
<status>OK</status>
<result>
<location>
<lat>-3.6000000</lat>
<lng>-45.3500000</lng>
</location>
<elevation>6.3086224</elevation>
<resolution>152.7032318</resolution>
</result>
</ElevationResponse>

ok?
OK.

n.yuan

  • Bull Frog
  • Posts: 348
Re: HTTPS request and read XML
« Reply #1 on: October 31, 2020, 08:52:03 AM »
There are a number of ways to get data from http response in the format of XML to deserialize the response string into an object of a class. Here are a couple of them:

1. use XmlSerializer. See this question and answer from StackOverFlow:

https://stackoverflow.com/questions/19942486/how-to-use-httpclient-to-read-an-xml-response

2. use XDocument.Parse() to convert the response string into a XmlDocument, then do whatever with the XmlDocument. See this question and answer

https://forums.asp.net/t/2160077.aspx?How+To+Parse+XML+Response+From+API

BTW, you can google for "HttpClient returns XML", which would bring you tons of links.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: HTTPS request and read XML
« Reply #2 on: October 31, 2020, 02:39:59 PM »
There are many ways to get data from the web and after retrieving the data using serialisation may be overkill so using XPath is a simple way of obtaining elements from XML, as this is a simple document you could simply use:

//elevation

but this can give you a list of all nodes of tag 'elevation' and there are ways to single out certain tags using criteria.
https://www.w3schools.com/xml/xpath_syntax.asp

hth

"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien