 		
 		public function setParent(parent:XML):void
 		{
-			if(_parent)
+			var oldParent:XML = _parent;
+			_parent = parent;
+			//assign first to prevent the possiblity of a recursive loop
+			if(oldParent)
 				_parent.removeChild(this);
-			_parent = parent;
 		}
 
 		public function setValue(value:String):void

				return indent + "<?" + name().localName + " " + _value + "?>";

			// We excluded the other types, so it's a normal element
			//TODO I'm here...
			// step 8.
			//ancestors
			if(!ancestors)

				{
					for(i=0;i<_attributes.length;i++)
					{
						if(_attributes[i].name().equals(attr.name()))
						{
							_attributes[i].setValue(value);
							return;
						}
						//addChild(_att)
					}
					if(value)
						attr.setValue(value);
					addChild(attr);
				}
				return;

			}
			if(attr.indexOf("xmlns") == 0)
			{
				//it's a namespace declaration
				//TODO This does not seem right.
				var ns:Namespace = new Namespace(value.toString());
				if(attr.indexOf("xmlns:") == 0)// it has a prefix
					ns.prefix = attr.split(":")[1];
