-1

私は DOM 要素に取り組んでいます。ルート ノードの名前を変更できますが、子ノードの名前も変更したい: 例:

<outcomes> to <ul> `
<para>     to <p>

これまでのところ:

要素 element = doc.getDocumentElement();

         // Create an element with the new name
            Element element2 = doc.createElement("topic");

         // Copy the attributes to the new element
            NamedNodeMap attrs = element.getAttributes();
            for (int i=0; i<attrs.getLength(); i++) {
                Attr attr2 = (Attr)doc.importNode(attrs.item(i), true);
                element2.getAttributes().setNamedItem(attr2);
           }

         // Move all the children
            while (element.hasChildNodes()) {
                element2.appendChild(element.getFirstChild());
            }

            // Replace the old node with the new node
            element.getParentNode().replaceChild(element2, element);

: ルート ノードの名前を変更しますが、子ノードの名前も変更したい Java を使用しています

これらの子ノードの名前を変更する簡単で具体的な方法はありますか

ありがとう

4

1 に答える 1

3

このためのメソッドは、Document.renameNodeというような目立たない場所にあります。

于 2012-07-30T17:30:51.450 に答える