<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2448.0">
<TITLE>RE: elt.detach()</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>>The only tricky thing is what to do if the Element being "detached" is a</FONT>
<BR><FONT SIZE=2>>root element, as shown above. Technically just removing a root elt from</FONT>
<BR><FONT SIZE=2>>its document makes the document no longer well-formed. So perhaps we</FONT>
<BR><FONT SIZE=2>>could do something like oldDoc.setRootElement(new</FONT>
<BR><FONT SIZE=2>>Element("placeholder"))?</FONT>
</P>
<P><FONT SIZE=2>>Ideas?</FONT>
</P>
<P><FONT SIZE=2>>-jh-</FONT>
</P>
<P><FONT SIZE=2>This was almost addressed in jdom beta 4 where the root element name was allowed to be changed with setName():</FONT>
</P>
<P><FONT SIZE=2>> [Vamshi] Method setName() is listed in the documentation but not implemented in the source.</FONT>
</P>
<P><FONT SIZE=2>> [jh] I don't know where you see it listed but it was intentionally removed. It shouldn't exist in current docs.</FONT>
</P>
<P><FONT SIZE=2>Sorry for using these fragments. This was the only reply I had left. I do not have the original content of that mail around 9/20/00 or later that week?</FONT></P>
<P><FONT SIZE=2>I thought Jason was quite efficient in including it, but I did not really understand why it was removed. That was one way of changing the parent/root element without additional object manipulations as such:</FONT></P>
<P><FONT SIZE=2>if (kid.getParent() != null) {</FONT>
<BR><FONT SIZE=2> kid.getParent().removeContent(kid);</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>if (kid.getDocument() != null) {</FONT>
<BR><FONT SIZE=2> // see later discussion</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>newParent.addContent(kid);</FONT>
</P>
<P><FONT SIZE=2>to simply:</FONT>
<BR> <FONT SIZE=2>newParent.addContent(kid.detach())</FONT>
</P>
<P><FONT SIZE=2>(+1 for the old way:</FONT>
<BR><FONT SIZE=2> old root name > new root name vs. old parent > detach children > make new parent > add detached children )</FONT>
</P>
<P><FONT SIZE=2>Even if the DocType were present, that could be changed easily to reflect the change and keep the doc well-formed.</FONT>
</P>
<P><FONT SIZE=2>Try this:</FONT>
<BR><FONT SIZE=2> 1. Element root = new Element("ROOT");</FONT>
<BR><FONT SIZE=2> 2. DocType dt = new DocType(root.getName());</FONT>
<BR><FONT SIZE=2> 3. Document d = new Document(root, dt);</FONT>
<BR><FONT SIZE=2> 4. root.addContent(new Element("CHILD"));</FONT>
<BR><FONT SIZE=2> 5. root.addChild(new Element("CHILD"));</FONT>
<BR>
<BR><FONT SIZE=2>Output: </FONT>
<BR> <FONT SIZE=2><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE ROOT><ROOT><CHILD /><CHILD /></ROOT></FONT>
</P>
<P><FONT SIZE=2>at an arbitrary point in processing down the line, add: </FONT>
<BR><FONT SIZE=2> 6. root = new Element("NEWROOT");</FONT>
<BR><FONT SIZE=2> 7. d.setRootElement(new Element("NEWROOT"));</FONT>
</P>
<P><FONT SIZE=2>Output:</FONT>
<BR> <FONT SIZE=2><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE ROOT><NEWROOT /></FONT>
</P>
<P><FONT SIZE=2>The children are missing. Also you need make sure to edit the DocType:</FONT>
</P>
<P><FONT SIZE=2> 8. dt = new DocType(root.getName());</FONT>
<BR><FONT SIZE=2> 9. d.setDocType(dt);</FONT>
</P>
<P><FONT SIZE=2>Output:</FONT>
<BR> <FONT SIZE=2><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE NEWROOT><NEWROOT /></FONT>
</P>
<P><FONT SIZE=2>A new requirement arises: The DocType may have system (p1) /public (p2) id that need to be preserved. If DocType also had a method setElementName() then we can change it as the root name changes without the need for a container for holding additional parameters (p1,p2). This would probably avoid additional checks and errors (?).</FONT></P>
<P><FONT SIZE=2>For the above, children still have to be moved in this case. With setName(string), setName(string, string) the children would be preserved with a new parent.</FONT></P>
<P><FONT SIZE=2>I changed the code at that time but had to undo it. Any other easier way out?</FONT>
</P>
<P><FONT SIZE=2>By the way its worth noting that code is very stable and just as fast as the Orcale Parser now. Is JDOM using XT too? XSLT is a bit slow.</FONT></P>
<P><FONT SIZE=2>What do the powers that be think?</FONT>
</P>
<P><FONT SIZE=2>- vamshi</FONT>
</P>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: jdom-interest-admin@jdom.org</FONT>
<BR><FONT SIZE=2>[<A HREF="mailto:jdom-interest-admin@jdom.org">mailto:jdom-interest-admin@jdom.org</A>]On Behalf Of</FONT>
<BR><FONT SIZE=2>jdom-interest-request@jdom.org</FONT>
<BR><FONT SIZE=2>Sent: Wednesday, December 27, 2000 11:12 PM</FONT>
<BR><FONT SIZE=2>To: jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>Subject: jdom-interest digest, Vol 1 #404 - 4 msgs</FONT>
</P>
<BR>
<P><FONT SIZE=2>Send jdom-interest mailing list submissions to</FONT>
<BR> <FONT SIZE=2>jdom-interest@jdom.org</FONT>
</P>
<P><FONT SIZE=2>To subscribe or unsubscribe via the World Wide Web, visit</FONT>
<BR> <FONT SIZE=2><A HREF="http://lists.denveronline.net/mailman/listinfo/jdom-interest" TARGET="_blank">http://lists.denveronline.net/mailman/listinfo/jdom-interest</A></FONT>
<BR><FONT SIZE=2>or, via email, send a message with subject or body 'help' to</FONT>
<BR> <FONT SIZE=2>jdom-interest-request@jdom.org</FONT>
</P>
<P><FONT SIZE=2>You can reach the person managing the list at</FONT>
<BR> <FONT SIZE=2>jdom-interest-admin@jdom.org</FONT>
</P>
<P><FONT SIZE=2>When replying, please edit your Subject line so it is more specific</FONT>
<BR><FONT SIZE=2>than "Re: Contents of jdom-interest digest..."</FONT>
</P>
<BR>
<P><FONT SIZE=2>Today's Topics:</FONT>
</P>
<P><FONT SIZE=2> 1. shema supported (Jian, David)</FONT>
<BR><FONT SIZE=2> 2. Re: Any expected release date for 1.0? (Jason Hunter)</FONT>
<BR><FONT SIZE=2> 3. Re: Suggestion (Jason Hunter)</FONT>
<BR><FONT SIZE=2> 4. elt.detach() (Jason Hunter)</FONT>
</P>
<P><FONT SIZE=2>--__--__--</FONT>
</P>
<P><FONT SIZE=2>Message: 1</FONT>
<BR><FONT SIZE=2>From: "Jian, David" <DJian@priceinteractive.com></FONT>
<BR><FONT SIZE=2>To: "'jdom-interest@jdom.org'" <jdom-interest@jdom.org></FONT>
<BR><FONT SIZE=2>Date: Wed, 27 Dec 2000 10:39:54 -0500</FONT>
<BR><FONT SIZE=2>Subject: [jdom-interest] shema supported</FONT>
</P>
<P><FONT SIZE=2>What's the version of w3 schena JDOM supported? Does B5 support 10/24/2000</FONT>
<BR><FONT SIZE=2>CR?</FONT>
</P>
<P><FONT SIZE=2>--__--__--</FONT>
</P>
<P><FONT SIZE=2>Message: 2</FONT>
<BR><FONT SIZE=2>Date: Fri, 22 Dec 2000 11:44:07 -0800</FONT>
<BR><FONT SIZE=2>From: Jason Hunter <jhunter@collab.net></FONT>
<BR><FONT SIZE=2>To: Michael Brennan <Michael_Brennan@Allegis.com></FONT>
<BR><FONT SIZE=2>CC: "'jdom-interest@jdom.org'" <jdom-interest@jdom.org></FONT>
<BR><FONT SIZE=2>Subject: Re: [jdom-interest] Any expected release date for 1.0?</FONT>
</P>
<P><FONT SIZE=2>It's an independent JSR. JAXP is likely to support JDOM once the JSR</FONT>
<BR><FONT SIZE=2>process has completed. The JDOM JSR is not listed because it's just</FONT>
<BR><FONT SIZE=2>getting started.</FONT>
</P>
<P><FONT SIZE=2>-jh-</FONT>
</P>
<P><FONT SIZE=2>Michael Brennan wrote:</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Thanks for the info. Is there an independent JSR for it or is it being</FONT>
<BR><FONT SIZE=2>> subsumed into JAXP? I wasn't able to find any reference to a JSR for this on</FONT>
<BR><FONT SIZE=2>> the Java Community Process web site.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Thanks.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> > -----Original Message-----</FONT>
<BR><FONT SIZE=2>> > From: Jason Hunter [<A HREF="mailto:jhunter@collab.net">mailto:jhunter@collab.net</A>]</FONT>
<BR><FONT SIZE=2>> > Sent: Thursday, December 21, 2000 11:49 PM</FONT>
<BR><FONT SIZE=2>> > To: Michael Brennan</FONT>
<BR><FONT SIZE=2>> > Cc: 'jdom-interest@jdom.org'</FONT>
<BR><FONT SIZE=2>> > Subject: Re: [jdom-interest] Any expected release date for 1.0?</FONT>
<BR><FONT SIZE=2>> ></FONT>
<BR><FONT SIZE=2>> ></FONT>
<BR><FONT SIZE=2>> > The API is getting pretty stable, but we're putting it through the JSR</FONT>
<BR><FONT SIZE=2>> > process, and that comes with mandatory review periods with formal</FONT>
<BR><FONT SIZE=2>> > community drafts, public drafts, and final drafts.</FONT>
<BR><FONT SIZE=2>> ></FONT>
<BR><FONT SIZE=2>> > -jh-</FONT>
</P>
<P><FONT SIZE=2>--__--__--</FONT>
</P>
<P><FONT SIZE=2>Message: 3</FONT>
<BR><FONT SIZE=2>Date: Fri, 22 Dec 2000 20:13:46 -0800</FONT>
<BR><FONT SIZE=2>From: Jason Hunter <jhunter@collab.net></FONT>
<BR><FONT SIZE=2>To: Mike Jennings <mjenning@islandnet.com></FONT>
<BR><FONT SIZE=2>CC: jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>Subject: Re: [jdom-interest] Suggestion</FONT>
</P>
<P><FONT SIZE=2>> Mike Jennings wrote:</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Hi,</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> What about adding a method to org.jdom.Element</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> public String getAttributeValue(String name, Namespace ns, String default)</FONT>
</P>
<P><FONT SIZE=2>There'd actually be two methods to add:</FONT>
</P>
<P><FONT SIZE=2>public String getAttributeValue(String name, String default)</FONT>
<BR><FONT SIZE=2>public String getAttributeValue(String name, Namespace ns, String</FONT>
<BR><FONT SIZE=2>default)</FONT>
</P>
<P><FONT SIZE=2>> Such that if the attribute named "name" does not exist, the String</FONT>
<BR><FONT SIZE=2>> "default" is returned.</FONT>
<BR><FONT SIZE=2>> This could be useful in cases where an XML file has default values for</FONT>
<BR><FONT SIZE=2>> attributes</FONT>
<BR><FONT SIZE=2>> that are not specified.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> What do the powers that be think of this idea?</FONT>
</P>
<P><FONT SIZE=2>Seems to fit in nicely. What do others think?</FONT>
</P>
<P><FONT SIZE=2>-jh-</FONT>
</P>
<P><FONT SIZE=2>--__--__--</FONT>
</P>
<P><FONT SIZE=2>Message: 4</FONT>
<BR><FONT SIZE=2>Date: Wed, 27 Dec 2000 22:38:48 -0800</FONT>
<BR><FONT SIZE=2>From: Jason Hunter <jhunter@collab.net></FONT>
<BR><FONT SIZE=2>To: JDOM Interest <jdom-interest@jdom.org></FONT>
<BR><FONT SIZE=2>Subject: [jdom-interest] elt.detach()</FONT>
</P>
<P><FONT SIZE=2>Hi,</FONT>
</P>
<P><FONT SIZE=2>I believe it would be useful to have an element.detach() method that</FONT>
<BR><FONT SIZE=2>removes an element from its parent (if there is a parent), and returns</FONT>
<BR><FONT SIZE=2>the detached element afterward. This simplifies the act of moving an</FONT>
<BR><FONT SIZE=2>element to a new location from this right now:</FONT>
</P>
<P><FONT SIZE=2>if (kid.getParent() != null) {</FONT>
<BR><FONT SIZE=2> kid.getParent().removeContent(kid);</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>if (kid.getDocument() != null) {</FONT>
<BR><FONT SIZE=2> // see later discussion</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>newParent.addContent(kid);</FONT>
</P>
<P><FONT SIZE=2>to simply:</FONT>
</P>
<P><FONT SIZE=2>newParent.addContent(kid.detach())</FONT>
</P>
<BR>
<P><FONT SIZE=2>The only tricky thing is what to do if the Element being "detached" is a</FONT>
<BR><FONT SIZE=2>root element, as shown above. Technically just removing a root elt from</FONT>
<BR><FONT SIZE=2>its document makes the document no longer well-formed. So perhaps we</FONT>
<BR><FONT SIZE=2>could do something like oldDoc.setRootElement(new</FONT>
<BR><FONT SIZE=2>Element("placeholder"))?</FONT>
</P>
<P><FONT SIZE=2>Ideas?</FONT>
</P>
<P><FONT SIZE=2>-jh-</FONT>
</P>
<BR>
<P><FONT SIZE=2>--__--__--</FONT>
</P>
<P><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>To control your jdom-interest membership:</FONT>
<BR><FONT SIZE=2><A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com" TARGET="_blank">http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</A></FONT>
</P>
<P><FONT SIZE=2>End of jdom-interest Digest</FONT>
</P>
</BODY>
</HTML>