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
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
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.
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;
}
std::string::find()andstd::string::substr(). You can use these to locate and extract the data you are looking for.