|
@@ -265,7 +265,9 @@ class Xml {
|
|
|
|
|
|
/**
|
|
/**
|
|
Adds a child node to the Document or Element.
|
|
Adds a child node to the Document or Element.
|
|
- One node can only be inside one given node which is indicated by the [parent] property.
|
|
|
|
|
|
+ A child node can only be inside one given parent node, which is indicated by the [parent] property.
|
|
|
|
+ If the child is already inside this Document or Element, there will be no effect.
|
|
|
|
+ If the child node was previously inside a different node, it will be moved to this Document or Element.
|
|
**/
|
|
**/
|
|
public function addChild( x : Xml ) : Void {
|
|
public function addChild( x : Xml ) : Void {
|
|
ensureElementType();
|
|
ensureElementType();
|
|
@@ -284,15 +286,26 @@ class Xml {
|
|
**/
|
|
**/
|
|
public function removeChild( x : Xml ) : Bool {
|
|
public function removeChild( x : Xml ) : Bool {
|
|
ensureElementType();
|
|
ensureElementType();
|
|
- return children.remove(x);
|
|
|
|
|
|
+ if (children.remove(x)) {
|
|
|
|
+ x.parent = null;
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
Inserts a child at the given position among the other childs.
|
|
Inserts a child at the given position among the other childs.
|
|
|
|
+ A child node can only be inside one given parent node, which is indicated by the [parent] property.
|
|
|
|
+ If the child is already inside this Document or Element, it will be removed and added at the new position.
|
|
|
|
+ If the child node was previously inside a different node, it will be moved to this Document or Element.
|
|
**/
|
|
**/
|
|
public function insertChild( x : Xml, pos : Int ) : Void {
|
|
public function insertChild( x : Xml, pos : Int ) : Void {
|
|
ensureElementType();
|
|
ensureElementType();
|
|
|
|
+ if (x.parent != null) {
|
|
|
|
+ x.parent.children.remove(x);
|
|
|
|
+ }
|
|
children.insert(pos, x);
|
|
children.insert(pos, x);
|
|
|
|
+ x.parent = this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -313,4 +326,4 @@ class Xml {
|
|
throw 'Bad node type, expected Element or Document but found $nodeType';
|
|
throw 'Bad node type, expected Element or Document but found $nodeType';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|