#include "xml_parser.hpp" #include "context.hpp" #include "attribute_template.hpp" #include "object_template.hpp" #include "group_template.hpp" namespace xios { namespace xml { string CXMLParser::currentIncludePath_="." ; string CXMLParser::updateIncludePath(const string& filePath) { string path = strTrim(filePath) ; vector match=splitRegex(path+'/',"/" ) ; // check if empty path bool isEmpty=true ; for(auto& m : match) if (!m.empty()) { isEmpty=false ; break ; } if (isEmpty) ERROR("string CXMLParser::updatePath(const string& filePath)", << "File path to include an new XML is empty :'"<& parseContextList) TRY { StdIFStream ifs ( filename.c_str() , StdIFStream::in ); if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) ERROR("void CXMLParser::ParseFile(const StdString & filename)", < file" ); CXMLParser::ParseStream(ifs, filename, parseContextList); } CATCH void CXMLParser::ParseString(const StdString & xmlContent) { StdIStringStream iss ( xmlContent /*, StdIStringStream::in*/ ); std::set contxtList; CXMLParser::ParseStream(iss,"string", contxtList); } void CXMLParser::ParseStream(StdIStream & stream, const string& fluxId, const std::set& parseContextList) { if (!stream.good()) ERROR("CXMLParser::ParseStream(const StdIStream & stream)", << "Bad xml stream !"); StdOStringStream oss; while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); try { rapidxml::xml_document doc; doc.parse<0>(const_cast(xmlcontent.c_str())); CXMLNode node(doc.first_node()); THashAttributes attributes; if (node.getElementName().compare(CXMLNode::GetRootName()) != 0) ERROR("CXMLParser::ParseStream(StdIStream & stream)", << "Root element should be named simulation (actual = \'" << node.getElementName() << "\')!"); try { CContextGroup* rootContext = CContext::getRoot() ; rootContext->parse(node, true, parseContextList) ; } catch(CException& e) { CException::StackInfo stk; stk.info.append("Exception occurred while parsing XML file \""); stk.info.append(attributes["src"]); stk.info.append("\".\n"); stk.file = FILE_NAME; stk.function = FUNCTION_NAME; stk.line = __LINE__; e.stack.push_back(stk); if (CXios::xiosStack) throw; else throw 0; } catch(...) { CException exc; CException::StackInfo stk; stk.info.append("Exception occurred while parsing XML file \""); stk.info.append(attributes["src"]); stk.info.append("\".\n"); stk.file = FILE_NAME; stk.function = FUNCTION_NAME; stk.line = __LINE__; exc.stack.push_back(stk); if (CXios::xiosStack) throw exc; else throw 0; } } catch (rapidxml::parse_error & exc) { const char* ptr = exc.where() ; const char* begin = xmlcontent.c_str() ; const char* content=oss.str().c_str() ; size_t pos=ptr-begin ; int lineNumber = 1 ; int columnNumber = 0 ; const char* line; const char* endLine; for(const char* i=content;i at character "<< pos<<" line "<