source: XMLIO_V2/dev/dev_rv/xmlio_xml_parser.hpp @ 91

Last change on this file since 91 was 91, checked in by hozdoba, 13 years ago

Corrections de plusieurs problÚmes.

File size: 1.9 KB
Line 
1#ifndef __XMLIO_XML_PARSER__
2#define __XMLIO_XML_PARSER__
3
4// Utilisation de la STL
5using std::string;
6
7namespace XMLIOSERVER
8{
9   namespace XML
10   {         
11      using XMLIOSERVER::Context;
12     
13      class XMLParser
14      {
15         public : 
16         
17            static void Parse(XMLNode& _node)
18            {
19               THashAttributes attributes;
20               
21              do {               
22                 // Traitement de l'identifiant
23                  _node.getAttributes(attributes);
24                           
25                  if (attributes.end() == attributes.find("id"))
26                  { WARNING("Le context ne sera pas traité car il n'est pas identifié !"); continue; }
27                 
28                  if( Context::HasObject(attributes["id"]))
29                  { WARNING("Le context ne sera pas traité car il existe déjà !"); continue; }
30                 
31                  Context::SetCurrentContext(attributes["id"]);
32                  Context& context = Context::CreateObject(attributes["id"]);
33                 
34                  context.parse(_node);
35                  attributes.clear();
36                 
37               } while (_node.goToNextElement());               
38            }   
39           
40            static bool CLASS_TEST(const string& file = string("/local/testsuite/iodef_test.xml"), ostream& log = std::clog)
41            {
42               ifstream istr( file.c_str() , ifstream::in );
43               XMLNode node = XMLNode::CreateNode(istr);
44               XMLParser::Parse(node);
45               log << "Nombre de contexts listés : " << Context::GetCurrentListObject().getSize() << " contre 2 attendus."<< std::endl;
46               log << "Test  XMLParser ... ok !" << std::endl;
47               return (true);
48            }
49                 
50      }; // class XMLParser     
51   }; // namespace XML
52
53};// namespace XMLIOSERVER
54
55
56#endif // __XMLIO_XML_PARSER__
Note: See TracBrowser for help on using the repository browser.