[jdom-interest] detach() [eg]

Per Kreipke per at onclave.com
Mon Apr 23 07:47:22 PDT 2001

I just subscribed to the list to find out the answer to the problem of
'replacing the root node of a document'. Fortuitious timing I guess.

> > I question the use case. How many times do you want to move the root
> > element of a document?
> Very seldom I would think.  It might be one way programmers try to change
> the dtd or schema of a document.

I'm not sure how to quantify 'seldom' but it's currently my chief concern
for two different reasons.

Use 1:

I'd like to push the root element inside of new element. In my case, the
example is that I'm taking a single item of type <foo> and pushing it down
into a set of <foo>.


<?xml version="1.0"?>


will become

<set attr1="ugh" attr2="blah">

The original <foo> tree is the input source, the rest is computed.

Perhaps my method is wrong and I should be building a separate document for
the output but I don't see why I can't do the above. Perhaps someone can
illustrate how.

Use 2:

Separately, I would like to do exactly what was questioned: "It might be one
way programmers try to change the dtd or schema of a document."

Basically, I'd like to rename the root of the document because its context
has now changed to a different DTD.

For example,

  <name first="Elmo" last="Schmotz"/>

Would change to:

  <name first="Elmo" last="Schmotz"/>

Can I do this without the detach() syntax currently in discussion?


More information about the jdom-interest mailing list