source: XIOS/dev/branch_yushan/src/xml_node.cpp @ 1103

Last change on this file since 1103 was 1103, checked in by yushan, 7 years ago

save modif. Todo: axis, domain, mesh, scalar, transformation

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 2.9 KB
Line 
1#include "xml_node.hpp"
2
3namespace xios
4{
5   namespace xml
6   {
7      /// ////////////////////// Définitions ////////////////////// ///
8
9      StdString CXMLNode::RootName("simulation");
10      // StdString CXMLNode::RootName = "simulation";
11
12      CXMLNode::CXMLNode(rapidxml::xml_node<char> * const root)
13         : node(root)
14         , level(0)
15      { /* Ne rien faire de plus */ }
16
17      CXMLNode::~CXMLNode(void)
18      { /* Ne rien faire de plus */ }
19
20      StdString CXMLNode::getElementName(void) const
21      { 
22         return (this->node->name()); 
23      }
24
25      bool CXMLNode::goToNextElement(void)
26      {
27         bool retvalue = false;
28         for(rapidxml::xml_node<char> * nextElement = this->node->next_sibling();
29                                      ; nextElement = this->node->next_sibling())
30         {
31            if (nextElement == NULL) break;
32            else if (nextElement->type() == rapidxml::node_element)
33            { 
34               node = nextElement;
35               return (!retvalue);
36            }
37         }
38         return (retvalue);
39      }
40
41      bool CXMLNode::goToChildElement(void)
42      {
43         bool retvalue = false;
44         rapidxml::xml_node<char> * nextElement = this->node->first_node();
45         if (nextElement != NULL)
46         {
47            for(;;nextElement = this->node->next_sibling())
48            {
49               if (nextElement == NULL) break;
50               else if (nextElement->type() == rapidxml::node_element)
51               { 
52                  node = nextElement;
53                  level++;
54                  return (!retvalue); 
55               }
56            }
57         }
58         return (retvalue);
59      }
60
61      bool CXMLNode::goToParentElement(void)
62      {
63         bool retvalue = false;
64         if (!(this->getElementName().compare(CXMLNode::RootName)) || (level == 0))
65            return (retvalue);
66         node = node->parent();
67         level--;
68         return (!retvalue);
69      }
70
71      bool CXMLNode::getContent(StdString & content)
72      {
73         if (this->node->value_size() == 0) return (false);
74         content.assign(this->node->value(), this->node->value_size());
75         return (true);
76      }
77
78      const StdString & CXMLNode::GetRootName(void)
79      { 
80         return (CXMLNode::RootName); 
81      }
82
83      THashAttributes CXMLNode::getAttributes(void) const
84      {
85         THashAttributes attributes;
86         rapidxml::xml_attribute<char> *currentAttr = NULL;
87
88         if ((currentAttr = this->node->first_attribute()) != NULL)
89         {
90            do 
91            {
92               attributes.insert(std::pair<StdString, StdString>
93                                (StdString(currentAttr->name()),
94                                 StdString(currentAttr->value())));
95            } while ((currentAttr = currentAttr->next_attribute()) != NULL);
96         }
97
98         return (attributes) ;
99      }
100
101   }// namespace xml
102} // namespace xios
Note: See TracBrowser for help on using the repository browser.