By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,202 Members | 1,341 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,202 IT Pros & Developers. It's quick & easy.

[Help, urgent] Move node!

P: n/a
Hi!
I want to move a node from file "film1" to "film2" that has tag
"FilmatoPartita".
I have write the codo below, but it don't do anything...I don't see the
error...
I have forgotten something? Maybe samething to write in the file "film2"?
Help...it's urgent..thanks!!!

import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node; // serve per spostare il nodo !
import org.w3c.dom.NodeList;
public class MoveNode {

public static void main(String[] args) {
try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();
Document doc1 = builder.parse( new File("film1.xml") );

Document doc2 = builder.parse( new File("film2.xml") );

System.out.println("prova");

Element firstRoot = doc1.getDocumentElement();

Element secondRoot = doc2.getDocumentElement();

NodeList nodi_figli =
firstRoot.getElementsByTagName("FilmatoPartita");
Element nodo_da_spostare = (Element)nodi_figli.item(0);

Node nuovo_nodo = doc2.importNode(nodo_da_spostare, true);
secondRoot.appendChild(nuovo_nodo);


} catch (Exception e) {
e.printStackTrace();
}
}

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


(¯`·.¸FlacK¸.·´¯) wrote:

I want to move a node from file "film1" to "film2" that has tag
"FilmatoPartita".
I have write the codo below, but it don't do anything...I don't see the
error... Node nuovo_nodo = doc2.importNode(nodo_da_spostare, true);
secondRoot.appendChild(nuovo_nodo);


You need to save the DOM tree that currently is in memory, how you do
that depends on the DOM implementation.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2

P: n/a
I use xerces...do you know?

"Martin Honnen" <ma*******@yahoo.de> ha scritto nel messaggio
news:41***********************@newsread4.arcor-online.net...


(¯`·.¸FlacK¸.·´¯) wrote:

I want to move a node from file "film1" to "film2" that has tag
"FilmatoPartita".
I have write the codo below, but it don't do anything...I don't see the
error...

Node nuovo_nodo = doc2.importNode(nodo_da_spostare, true);
secondRoot.appendChild(nuovo_nodo);


You need to save the DOM tree that currently is in memory, how you do
that depends on the DOM implementation.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

P: n/a


(¯`·.¸FlacK¸.·´¯) wrote:
I use xerces...do you know?


There is a serializer in Xerces:
http://xml.apache.org/xerces2-j/java...erializer.html
http://xml.apache.org/xerces2-j/java...erializer.html

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.