add convenience methods
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 0467d17..f260513 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -1962,41 +1962,34 @@
}
-XMLElement* XMLElement::PushNewChildElement(const char* name)
+XMLElement* XMLElement::InsertNewChildElement(const char* name)
{
- XMLElement* element = _document->NewElement(name);
- // by construction, the new element has the same Document, so this
- // call will always succeed
- InsertEndChild(element);
- return element;
+ XMLElement* node = _document->NewElement(name);
+ return InsertEndChild(node) ? node : 0;
}
-XMLComment* XMLElement::PushNewChildComment(const char* comment)
+XMLComment* XMLElement::InsertNewComment(const char* comment)
{
- XMLComment* element = _document->NewComment(comment);
- InsertEndChild(element);
- return element;
+ XMLComment* node = _document->NewComment(comment);
+ return InsertEndChild(node) ? node : 0;
}
-XMLText* XMLElement::PushNewChildText(const char* text)
+XMLText* XMLElement::InsertNewText(const char* text)
{
- XMLText* element = _document->NewText(text);
- InsertEndChild(element);
- return element;
+ XMLText* node = _document->NewText(text);
+ return InsertEndChild(node) ? node : 0;
}
-XMLDeclaration* XMLElement::PushNewChildDeclaration(const char* text)
+XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text)
{
- XMLDeclaration* element = _document->NewDeclaration(text);
- InsertEndChild(element);
- return element;
+ XMLDeclaration* node = _document->NewDeclaration(text);
+ return InsertEndChild(node) ? node : 0;
}
-XMLUnknown* XMLElement::PushNewUnknown(const char* text)
+XMLUnknown* XMLElement::InsertNewUnknown(const char* text)
{
- XMLUnknown* element = _document->NewUnknown(text);
- InsertEndChild(element);
- return element;
+ XMLUnknown* node = _document->NewUnknown(text);
+ return InsertEndChild(node) ? node : 0;
}
diff --git a/tinyxml2.h b/tinyxml2.h
index 25b59c3..cb8bad5 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -1646,15 +1646,15 @@
Convenience method to create a new XMLElement and add it as last (right)
child of this node. Returns the created and inserted element.
*/
- XMLElement* PushNewChildElement(const char* name);
- /// See PushNewChildElement()
- XMLComment* PushNewChildComment(const char* comment);
- /// See PushNewChildElement()
- XMLText* PushNewChildText(const char* text);
- /// See PushNewChildElement()
- XMLDeclaration* PushNewChildDeclaration(const char* text);
- /// See PushNewChildElement()
- XMLUnknown* PushNewUnknown(const char* text);
+ XMLElement* InsertNewChildElement(const char* name);
+ /// See InsertNewChildElement()
+ XMLComment* InsertNewComment(const char* comment);
+ /// See InsertNewChildElement()
+ XMLText* InsertNewText(const char* text);
+ /// See InsertNewChildElement()
+ XMLDeclaration* InsertNewDeclaration(const char* text);
+ /// See InsertNewChildElement()
+ XMLUnknown* InsertNewUnknown(const char* text);
// internal: