Ignore:
Timestamp:
01/21/14 09:40:14 (10 years ago)
Author:
ymipsl
Message:

Enhancement :

  • Improving error message occuring along the xml parsing : position (line number, column) is now indicated
  • New executable : parse_xml.exe : parse the xml files and reports potential error

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/xml_parser_impl.hpp

    r352 r462  
    99   namespace xml 
    1010   { 
    11      template <class T> void CXMLParser::ParseInclude(StdIStream & stream, T& object) 
     11     template <class T> void CXMLParser::ParseInclude(StdIStream & stream, const string& fluxId,  T& object) 
    1212      { 
    1313         StdOStringStream oss; 
    14          while(!stream.eof() && !stream.fail ()) 
    15             oss.put(stream.get()); 
     14         while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); 
     15         const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 
    1616         try 
    1717         { 
    18             const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 
    1918            rapidxml::xml_document<char> doc; 
    2019            doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); 
     
    2423         catch (rapidxml::parse_error & exc) 
    2524         { 
    26             ERROR("CXMLParser::ParseStream(StdIStream & stream)", 
    27                   << "RapidXML error : " << exc.what() << " !"); 
     25             const char* ptr = exc.where<char>() ; 
     26            const char* begin = xmlcontent.c_str() ; 
     27            const char* content=oss.str().c_str() ; 
     28            size_t pos=ptr-begin ; 
     29            int lineNumber = 1 ; 
     30            int columnNumber = 0 ; 
     31            const char* line; 
     32            const char* endLine; 
     33             
     34            for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;} 
     35            for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ; 
     36            string strLine(line,endLine-line) ; 
     37                   
     38            ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl 
     39                  << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl 
     40                  << strLine<<endl 
     41                  << string(columnNumber-1,'x')<<'^'<<endl 
     42                  <<" Error : " << exc.what() ) 
    2843         } 
    2944      } 
Note: See TracChangeset for help on using the changeset viewer.