Digesterについて

Struts内でも使われているXMLJavaオブジェクトのマッピングツールのJakarta Commons Digesterというのがありますが、どうなんでしょうか??他にもJAXBなんてのもありますが。とりあえず使ってみます。以下、参考ページです。

【追記】
ちょっと使ってみました。といっても、↑のページにあるサンプル程度ですが。確かに、自分でSAXとか使うよりはぜんぜん楽ですね。今後は設定ファイルなどXMLにして行こうかと思います。

DOMノードの移動

ちょっとJavaにて、XMLファイルの操作をしていたのですが、2つのDOMのDocument間でNodeを移動する場合は、一度importNode()してからappendするのですね。知りませんでした。。

            DOMParser parser = new DOMParser();  

            // Create the first document          
            parser.parse(new InputSource(args[0]));
            Document doc1 = parser.getDocument();

            // Create the second document
            parser.parse(new InputSource(args[1]));
            Document doc2 = parser.getDocument();

            // Get root of first document
            Element firstRoot = doc1.getDocumentElement();

            // Get Node to move
            Element secondRoot = doc2.getDocumentElement();
            NodeList kids = secondRoot.getElementsByTagName("game");
            Element oneToMove = (Element)kids.item(0);

            // Add to first document
            firstRoot.appendChild(oneToMove);

ヒント: DOMノードの移動developerWorks) より