I have the following input
"<?xml version="1.0"?>\r\n<MODEL-LIST>\r\n<MODEL ID="450 MHz Default" TYPE="Basic Model" />\r\n<MODEL ID="900 MHz Default" TYPE="Enhanced Model" />"
and want to parse to get the output in the following format.
const char output[100] = "450 MHz Default-Basic Model, 900 MHz Default-Enhanced Model";
I have written following code, any commnets or suggestions helpful
Code:const char* buf = xmlStr;
int bstrlen = xmlStr.length();
std::string str(buf ? buf : "", bstrlen);
// Vector of string to save tokens
vector <string> tokens;
vector <string> models;
// stringstream class check1
stringstream check1(str);
string intermediate;
// Tokenizing w.r.t. space ' '
while (std::getline(check1, intermediate, '\n'))
{
tokens.push_back(intermediate);
}
for (string token : tokens)
{
std::string first = "MODEL ID="";
std::size_t firstLim = token.find(first);
std::string last = "" TYPE="";
std::size_t lastLim = token.find(last);
if ( (firstLim != std::string::npos) && (lastLim != std::string::npos) )
{
std::string modelid = token.substr(firstLim, lastLim - firstLim);
int i = first.size();
modelid = modelid.substr(first.size());
models.push_back(modelid);
std::string modeltype = token.substr(lastLim);
modeltype = modeltype.substr(last.size());
std::string elem = """;
std::size_t elemLim = token.find(elem);
modeltype = modeltype.substr(elemLim);
}
}

