Compilable and runnable:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import org.jdom2.Document;
import org.jdom2.Element;
public class JDomQuestion
{
public static void main(String[] args)
{
JDomQuestion jDomQuestion = new JDomQuestion();
jDomQuestion.doit();
}
private void doit()
{
Document fakeDocumentWithARoot = createFakeDocumentWithARoot();
Document emptyFakeDocument = createEmptyFakeDocument();
transferRootToEmptyDocument(fakeDocumentWithARoot, emptyFakeDocument);
}
private void transferRootToEmptyDocument(Document fakeDocumentWithARoot, Document emptyFakeDocument)
{
Element rootElement = fakeDocumentWithARoot.getRootElement();
emptyFakeDocument.setRootElement(rootElement); // Boom ! Here is your exact error.
}
private Document createEmptyFakeDocument()
{
return new Document();
}
private Document createFakeDocumentWithARoot()
{
Document fakeDocument = new Document();
fakeDocument.setRootElement(new Element("My_name_is_Ozymandias_Root_of_Roots" +
"Look_on_my_bug_ye_Mighty_and_despair."));
return fakeDocument;
}
}
Ted Gress wrote:*That's* the part I'm having trouble with. I tried the detach and removecontent methods without much luck.
Ted Gress wrote:But it appears that the node is not being detached or the content is not being removed.
Ted Gress wrote:? Anybody have any ideas
why detach() and removecontent() might not work?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions