浏览代码

New API for XMLElement

    bool AppendChild(XMLElement element, bool asCopy=false)
    bool Remove()
Rokas Kupstys 8 年之前
父节点
当前提交
e1409e6ddc
共有 2 个文件被更改,包括 24 次插入0 次删除
  1. 20 0
      Source/Urho3D/Resource/XMLElement.cpp
  2. 4 0
      Source/Urho3D/Resource/XMLElement.h

+ 20 - 0
Source/Urho3D/Resource/XMLElement.cpp

@@ -124,6 +124,26 @@ XMLElement XMLElement::GetOrCreateChild(const char* name)
         return CreateChild(name);
 }
 
+bool XMLElement::AppendChild(XMLElement element, bool asCopy)
+{
+    if (!element.file_ || (!element.node_ && !element.xpathNode_) || !file_ || (!node_ && !xpathNode_))
+        return false;
+
+    const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_);
+    const pugi::xml_node& child = element.xpathNode_ ? element.xpathNode_->node() : pugi::xml_node(element.node_);
+
+    if (asCopy)
+        const_cast<pugi::xml_node&>(node).append_copy(child);
+    else
+        const_cast<pugi::xml_node&>(node).append_move(child);
+    return true;
+}
+
+bool XMLElement::Remove()
+{
+    return GetParent().RemoveChild(*this);
+}
+
 bool XMLElement::RemoveChild(const XMLElement& element)
 {
     if (!element.file_ || (!element.node_ && !element.xpathNode_) || !file_ || (!node_ && !xpathNode_))

+ 4 - 0
Source/Urho3D/Resource/XMLElement.h

@@ -70,6 +70,10 @@ public:
     XMLElement GetOrCreateChild(const String& name);
     /// Return the first child element with name or create if does not exist.
     XMLElement GetOrCreateChild(const char* name);
+    /// Append element. If asCopy is set to true then original element is copied and appended, otherwise specified element is appended.
+    bool AppendChild(XMLElement element, bool asCopy=false);
+    /// Remove element from it's parent.
+    bool Remove();
     /// Remove a child element. Return true if successful.
     bool RemoveChild(const XMLElement& element);
     /// Remove a child element by name. Return true if successful.