XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
xml_node.cpp
Aller à la documentation de ce fichier.
1 #include "xml_node.hpp"
2 #include <boost/algorithm/string.hpp>
3 
4 namespace xios
5 {
6  namespace xml
7  {
9 
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 
18  { /* Ne rien faire de plus */ }
19 
21  {
22  return (this->node->name());
23  }
24 
26  {
27  bool retvalue = false;
28  for(rapidxml::xml_node<char> * nextElement = this->node->next_sibling();
29  ; nextElement = nextElement->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 
42  {
43  bool retvalue = false;
44  rapidxml::xml_node<char> * nextElement = this->node->first_node();
45  if (nextElement != NULL)
46  {
47  for(;;nextElement = nextElement->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 
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 */
79  {
80  content="" ;
81  bool retvalue = false;
82 
83  rapidxml::xml_node<char> * nextElement = this->node->first_node();
84  while (nextElement != NULL)
85  {
86  if (nextElement->type() == rapidxml::node_data) content=content+std::string(nextElement->value(),nextElement->value_size());
87  nextElement = nextElement->next_sibling();
88  }
89  boost::algorithm::replace_all(content,"\n"," ") ;
90  boost::algorithm::trim(content) ;
91  if (content.size()==0) return false ;
92  else return true ;
93  }
94 
96  {
97  return (CXMLNode::RootName);
98  }
99 
101  {
102  THashAttributes attributes;
103  rapidxml::xml_attribute<char> *currentAttr = NULL;
104 
105  if ((currentAttr = this->node->first_attribute()) != NULL)
106  {
107  do
108  {
109  attributes.insert(std::pair<StdString, StdString>
110  (StdString(currentAttr->name()),
111  StdString(currentAttr->value())));
112  } while ((currentAttr = currentAttr->next_attribute()) != NULL);
113  }
114 
115  return (attributes) ;
116  }
117 
118  }// namespace xml
119 } // namespace xios
StdString getElementName(void) const
Accesseurs ///.
Definition: xml_node.cpp:20
bool goToParentElement(void)
Definition: xml_node.cpp:61
bool getContent(StdString &content)
Definition: xml_node.cpp:78
CXMLNode(void)
Constructeurs ///.
static const StdString & GetRootName(void)
Accesseurs statiques ///.
Definition: xml_node.cpp:95
static StdString RootName
////////////////////// Définitions ////////////////////// ///
Definition: xml_node.hpp:50
std::string StdString
Definition: xios_spl.hpp:48
#define xios(arg)
bool goToNextElement(void)
Mutateurs ///.
Definition: xml_node.cpp:25
rapidxml::xml_node< char > * node
Definition: xml_node.hpp:47
std::map< StdString, StdString > THashAttributes
////////////////////// Déclarations ////////////////////// ///
Definition: xml_node.hpp:15
~CXMLNode(void)
Destructeur ///.
Definition: xml_node.cpp:17
THashAttributes getAttributes(void) const
Definition: xml_node.cpp:100
bool goToChildElement(void)
Definition: xml_node.cpp:41