c++ - How can i get xml line number from ptree exception -


i using boost ptree read xml file this:

ptree mytree; ... /*open xml file*/ try{     mytree.get<string>(s); } catch(boost::exception const&  ex) { /*get useful info!*/ } 

i know can use what() function, produces error , strings sent.

is there way more useful information line numbers in xml relevant call?

if want detect malformed xml (as opposed xml documents don't contain values expect, in case line numbers aren't feasible obtain):

#include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp>  int main(int argc, char* argv[]) {   boost::property_tree::ptree pt;   try {     read_xml(argv[1], pt);   } catch (const boost::property_tree::xml_parser::xml_parser_error& ex) {     std::cerr << "error in file " << ex.filename() << " line " << ex.line() << std::endl;   } } 

now given t.xml not valid xml document:

$ a.out t.xml error in file t.xml @ line 10 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -