1

I am trying to parse this XML Yahoo feed.

How do i like get each record into an array in C++ like create a structure

then got those variable and record each element inside the structure.

In the first place, how do i get the value out

Thanks

1
  • C++ has std::string::find() and std::string::substr(). You can use these to locate and extract the data you are looking for. Commented Jul 23, 2012 at 15:47

2 Answers 2

5

You may want to see if the given page offers output in a JSON format. Then you can simply request the value instead of messing around with HTML. The Yahoo! Finance site may even offer an API that you can use to easily request the value.

Sign up to request clarification or add additional context in comments.

1 Comment

I found the api, but how do i parse this to get e.g USD/SGD
0

If you want to mess with html code:

#include <iostream>
#include <fstream>
int main() {
  std::ifstream ifile("in.html");
  std::string line;
  std::string ndl("<span id=\"yfs_l10_sgdmyr=x\">");
  while(ifile.good()){ 
    getline(ifile, line);
    if (line.size()) {
      size_t spos, epos;
      if ((spos = line.find(ndl)) != std::string::npos) {
        spos += ndl.size();
        if ((epos = line.find(std::string("</span>"), spos)) != std::string::npos) {
          std::cout << line.substr(spos, epos-spos) << std::endl;
        }   
      }   
    }   
  }   
  return 0;
}

2 Comments

do you have the in.html file?
i was parsing this page link , i use lynx -source URL > buffer.txt , then the buffer is actually the source code. i changed your sgdmyr to usdsgd, but seems doesnt work

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.