1

I'm trying to parse data from the web, basically, from an API (Google Finance API:: http://www.google.com/ig/api?stock=AAPL).

How do I approach this? Could I use XMLDocument to do this or MSXML2?

The XML looks like this

<xml_api_reply version="1">
  <finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
     <symbol data="AAPL"/>
  </finance>
</xml_api_reply>

I've only worked where the node root doesn't have the name of the thing I need. So, how would I specifically retrieve the data for the node symbol?

This is what I've currently got:

Function get_ftseindex()
    Dim objXML As New System.Xml.XmlDocument
    objXML.Load("http://www.google.com/ig/api?stock=UKX")
End Function

1 Answer 1

1

You should be able to use an XDocument:

Public Sub Test()
    Dim sAPIUrl As String = "http://www.google.com/ig/api?stock=AAPL"
    Dim oDocument As XDocument = XDocument.Load(sAPIUrl)
    Dim sCompany As String = GetData(oDocument, "company")
    Dim sExchange As String = GetData(oDocument, "exchange")
    Dim dLast As Double = CDbl(GetData(oDocument, "last"))
    Dim dHigh As Double = CDbl(GetData(oDocument, "high"))
    Dim dLow As Double = CDbl(GetData(oDocument, "low"))
End Sub

Private Function GetData(ByVal doc As XDocument, ByVal name As String) As String
    Return doc.Root.Element("finance").Element(name).Attribute("data").Value
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.