Skip to content
Browse files

Implement importXMLBuilder()

  • Loading branch information...
1 parent a824ee0 commit 5424f0a4845748963f56004f07f3ebd9e03ce112 @piroor piroor committed Jul 26, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/XMLFragment.coffee
View
21 src/XMLFragment.coffee
@@ -255,6 +255,27 @@ class XMLFragment
@parent.children[i + 1]
+ # Clones self
+ clone: (deep) ->
+ clonedSelf = new XMLFragment @parent, @name, @attributes, @value
+ if deep
+ @children.forEach (child) ->
+ clonedChild = child.clone(deep)
+ clonedChild.parent = clonedSelf
+ clonedSelf.children.push clonedChild
+ return clonedSelf
+
+
+ # Imports cloned root from another XMLBuilder
+ importXMLBuilder: (xmlbuilder) ->
+ root = xmlbuilder.children[xmlbuilder.children.length - 1]
+ clonedRoot = root.clone(true)
+ clonedRoot.parent = this
+ @children.push clonedRoot
+ clonedRoot.isRoot = false
+ return @
+
+
# Adds or modifies an attribute
#
# `name` attribute name

0 comments on commit 5424f0a

Please sign in to comment.
Something went wrong with that request. Please try again.