You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ha...@apache.org on 2016/04/11 00:48:21 UTC

[10/49] git commit: [flex-asjs] [refs/heads/develop] - removeChild()

removeChild()


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/eb91e10f
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/eb91e10f
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/eb91e10f

Branch: refs/heads/develop
Commit: eb91e10f4a3d387bcd4d7fc74474b804072ad1f7
Parents: d2b32b8
Author: Harbs <ha...@in-tools.com>
Authored: Sun Feb 7 09:32:54 2016 +0200
Committer: Harbs <ha...@in-tools.com>
Committed: Sun Feb 7 09:32:54 2016 +0200

----------------------------------------------------------------------
 frameworks/projects/XML/as/src/XML.as | 62 +++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/eb91e10f/frameworks/projects/XML/as/src/XML.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/as/src/XML.as b/frameworks/projects/XML/as/src/XML.as
index c9da8a7..7736133 100644
--- a/frameworks/projects/XML/as/src/XML.as
+++ b/frameworks/projects/XML/as/src/XML.as
@@ -1114,14 +1114,73 @@ package
 				6. Let x.[[Length]] = x.[[Length]] - dp
 				7. Return true.
 			*/
-			if(child.nodeKind())
 			var removed:XML;
+			if(!child)
+				return false;
+			if(!_attributes)
+				return false;
+
+			if(!(child is XML))
+				return removeChildByName(child);
+			
+			if(child.nodeKind() == "attribute")
+			{
+				for(i=0;i<_attributes.length;i++)
+				{
+					if(child.equals(_attributes[i]))
+					{
+						removed = _attributes[i];
+						removed.setParent(null);
+						_attributes.splice(i,1);
+						return true;
+					}
+				}
+			}
 			var idx:int = _children.indexOf(child);
+			if(idx < 0)
+				return false;
 			removed = _children.splice(idx,1);
 			child.setParent(null);
 			return removed;
 		}
+		private function removeChildByName(name:*):Boolean
+		{
+			var i:int;
+			name = toXMLName(name);
+			child = null;
+			var removedItem:Boolean = false;
+			if(name.isAttribute)
+			{
+				if(!_attributes)
+					return false;
 
+				for(i=_attributes.length-1;i>=0;i--)
+				{
+					if(_attributes[i].name().matches(name))
+					{
+						child = _attributes[i];
+						child.setParent(null);
+						_attributes.splice(i,1);
+						removedItem = true;
+					}
+				}
+				return removedItem;
+			}
+			//QUESTION am I handling non-elements correctly?
+			if(!_children)
+				return false;
+			for(i=_children.length-1;i>=0;i--)
+			{
+				if(_children[i].name().matches(name))
+				{
+					child = _children[i];
+					child.setParent(null);
+					_children.splice(i,1);
+					removedItem = true;
+				}
+			}
+			return removedItem;
+		}
 		public function removeChildAt(index:int):void
 		{
 			/*
@@ -1138,6 +1197,7 @@ package
 				  b. Return true
 				3. Else throw a TypeError exception
 			*/
+			//Do nothing for XML objects?
 		}
 
 		/**