I'm trying to parse this string and retrieve the "sid" and the "Type". I have the following code. It is crashing at the get_child
line and I'm not entirely sure why...
const boost::property_tree::ptree& empty_ptree(){
static boost::property_tree::ptree t;
return t;
}
int _tmain(int argc, _TCHAR* argv[])
{
struct SXMLElements
{
std::string strSessionId;
unsigned int uiTypeOfNotification;
};
std::string strXMLText = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n"
"<NotificationSet vers=\"1.0\" svcid=\"session\" notid=\"42\">\r\n" "<Notification><![CDATA[<SessionNotification vers=\"1.0\" notid=\"42\">\r\n"
"<Session sid=\"sdfkljdsfkjjsf\">\r\n" "<Property name=\"CharSet\" value=\"UTF-8\"></Property>\r\n"
"</Session>\r\n" "<Type>5</Type>\r\n"
"<Time>324242</Time>\r\n"
"</SessionNotification>]]></Notification>\r\n"
"</NotificationSet>";
//// Parse the HTTP header Status line.
std::stringstream ss( strXMLText );
boost::property_tree::ptree xmlResponse;
//if (strXMLText.size() > 0)
//{
std::istringstream isResponse (strXMLText);
boost::property_tree::read_xml(isResponse, xmlResponse);
SXMLElements sXmlElem;
//const boost::property_tree::ptree & formats = xmlResponse.get_child("NotificationSet.Notification.Session", empty_ptree());
BOOST_FOREACH( boost::property_tree::ptree::value_type const& v, xmlResponse.get_child("NotificationSet.Notification.SessionNotification.Session") )
{
sXmlElem.strSessionId = xmlResponse.get<std::string>("<xmlattr>.sid", "");
sXmlElem.uiTypeOfNotification = xmlResponse.get<unsigned int>("Type", 0);
// }
}
//}
return 0;
}
Can anyone spot what I might be doing wrong?