好吧,亚伦·迪古拉(Aaron
Digulla)在速度上击败了我。也必须自己弄清楚。我没有使用
cnl.item(i+1)但是
nextSibling():
Element newElement = doc.createElement(stepType); // Element to be inserted newElement.setAttribute("name", stepName);elem.getParentNode().insertBefore(newElement, elem.getNextSibling());您不能在指定的索引处插入节点。唯一的节点插入方法是
appendChild(Node node) //appends the given child to the end of the list of children
和
insertBefore(Node new, Node child) //inserts "new" into the list, before the 'child' node.
如果有insertAfter(Node new,Node child)方法,这对您来说将非常容易。但不幸的是,没有。



