Commit 63a4e64b6c552f320b5fe0a16ed794dddcd0e1a6

Authored by Jürgen Knödlseder
1 parent 8cd0056b

Forbid appending of text segement to a text node.

Showing 1 changed file with 13 additions and 3 deletions
src/xml/GXmlNode.cpp
... ... @@ -36,7 +36,8 @@
36 36 /* __ Method name definitions ____________________________________________ */
37 37 #define G_ACCESS "GXmlNode::operator[](int&)"
38 38 #define G_SET "GXmlNode::set(int&, GXmlNode&)"
39   -#define G_APPEND "GXmlNode::append(GXmlNode&)"
  39 +#define G_APPEND1 "GXmlNode::append(std::string&)"
  40 +#define G_APPEND2 "GXmlNode::append(GXmlNode&)"
40 41 #define G_INSERT "GXmlNode::insert(int&, GXmlNode&)"
41 42 #define G_REMOVE "GXmlNode::remove(int&)"
42 43 #define G_ELEMENT1 "GXmlNode* GXmlNode::element(int&)"
... ... @@ -266,7 +267,7 @@ GXmlNode* GXmlNode::append(const GXmlNode& node)
266 267 std::string msg = "Invalid attempt to append root note (GXmlDocument)"
267 268 " to a XML node. There can only be one root node in"
268 269 " an XML document.";
269   - throw GException::invalid_argument(G_APPEND, msg);
  270 + throw GException::invalid_argument(G_APPEND2, msg);
270 271 }
271 272  
272 273 // Make sure that the current node is not a text node as nothing can be
... ... @@ -274,7 +275,7 @@ GXmlNode* GXmlNode::append(const GXmlNode& node)
274 275 if (this->type() == NT_TEXT) {
275 276 std::string msg = "Invalid attempt to append a XML node to a text node"
276 277 " (GXmlText). Nothing can be appended to a text node.";
277   - throw GException::invalid_value(G_APPEND, msg);
  278 + throw GException::invalid_value(G_APPEND2, msg);
278 279 }
279 280  
280 281 // Clone child node
... ... @@ -301,6 +302,15 @@ GXmlNode* GXmlNode::append(const GXmlNode& node)
301 302 ***************************************************************************/
302 303 GXmlElement* GXmlNode::append(const std::string& segment)
303 304 {
  305 + // Make sure that the current node is not a text node as nothing can be
  306 + // appended to a text node.
  307 + if (this->type() == NT_TEXT) {
  308 + std::string msg = "Invalid attempt to append the text segment \""+
  309 + segment+"\" to a text node (GXmlText). Nothing can"
  310 + " be appended to a text node.";
  311 + throw GException::invalid_value(G_APPEND1, msg);
  312 + }
  313 +
304 314 // Create a new XML child element from the text segment
305 315 GXmlElement* ptr = new GXmlElement(segment);
306 316  
... ...