Line | |
---|
1 | #ifndef __XMLIO_CXMLParser__ |
---|
2 | #define __XMLIO_CXMLParser__ |
---|
3 | |
---|
4 | /// xmlioserver headers /// |
---|
5 | #include "xmlioserver_spl.hpp" |
---|
6 | #include "exception.hpp" |
---|
7 | #include "xml_node.hpp" |
---|
8 | |
---|
9 | |
---|
10 | namespace xmlioserver |
---|
11 | { |
---|
12 | namespace xml |
---|
13 | { |
---|
14 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
15 | class CXMLParser |
---|
16 | { |
---|
17 | public : |
---|
18 | |
---|
19 | static void ParseFile(const StdString & filename); |
---|
20 | static void ParseString(const StdString & xmlContent); |
---|
21 | static void ParseStream(StdIStream & stream); |
---|
22 | template <class T> |
---|
23 | static inline void ParseInclude(StdIStream & stream, T & object); |
---|
24 | |
---|
25 | }; //class CXMLParser |
---|
26 | |
---|
27 | template <class T> |
---|
28 | void CXMLParser::ParseInclude(StdIStream & stream, T& object) |
---|
29 | { |
---|
30 | StdOStringStream oss; |
---|
31 | while(!stream.eof() && !stream.fail ()) |
---|
32 | oss.put(stream.get()); |
---|
33 | try |
---|
34 | { |
---|
35 | const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); |
---|
36 | rapidxml::xml_document<char> doc; |
---|
37 | doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); |
---|
38 | CXMLNode node(doc.first_node()); |
---|
39 | object.parse(node); |
---|
40 | } |
---|
41 | catch (rapidxml::parse_error & exc) |
---|
42 | { |
---|
43 | ERROR("CXMLParser::ParseStream(StdIStream & stream)", |
---|
44 | << "RapidXML error : " << exc.what() << " !"); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | }// namespace xml |
---|
49 | } // namespace xmlioserver |
---|
50 | |
---|
51 | #endif // __XMLIO_CXMLParser__ |
---|
Note: See
TracBrowser
for help on using the repository browser.