final DocumentImpl owner = (DocumentImpl)getOwnerDocument();
	public void removeAppendAttributes(Txn transaction, NodeList removeList, NodeList appendList) {        final DocumentImpl owner = (DocumentImpl)getOwnerDocument();		try {			if (removeList != null) {				try {					for (int i=0; i<removeList.getLength(); i++) {						Node oldChild = removeList.item(i);						if (!(oldChild instanceof StoredNode))							throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "wrong node type");						StoredNode old = (StoredNode) oldChild;						if (!old.nodeId.isChildOf(nodeId))							throw new DOMException(DOMException.NOT_FOUND_ERR, "node " + old.nodeId.getParentId() + 									" is not a child of element " + nodeId);						getBroker().removeNode(transaction, old, old.getPath(), null);						children--;						attributes--;					}				} finally {					getBroker().endRemove();				}			}			if (children == 0) {			   appendChildren(transaction, nodeId.newChild(), -1, 					   new NodeImplRef(this), getPath(), appendList, true);			} else {		        if (attributes == 0) {		        	StoredNode firstChild = (StoredNode) getFirstChild();		        	NodeId newNodeId = firstChild.nodeId.insertBefore();                    appendChildren(transaction, newNodeId, -1, new NodeImplRef(this), getPath(), appendList, true);                    		        } else {		        	AttribVisitor visitor = new AttribVisitor();			        accept(visitor);			        NodeId firstChildId = visitor.firstChild == null ? null : visitor.firstChild.nodeId;			        NodeId newNodeId = visitor.lastAttrib.nodeId.insertNode(firstChildId);                    appendChildren(transaction, newNodeId, -1, new NodeImplRef(visitor.lastAttrib),                     		getPath(), appendList, true);		        }			}			attributes += appendList.getLength();		} finally {            getBroker().updateNode(transaction, this);            getBroker().flush();		}	}