[jdom-interest] RE: elt.detach()

Vamshi Reddy Vamshi.Reddy at whn.com
Thu Dec 28 12:26:31 PST 2000


>The only tricky thing is what to do if the Element being "detached" is a
>root element, as shown above.  Technically just removing a root elt from
>its document makes the document no longer well-formed.  So perhaps we
>could do something like oldDoc.setRootElement(new
>Element("placeholder"))?

>Ideas?

>-jh-

This was almost addressed in jdom beta 4 where the root element name was
allowed to be changed with setName():

> [Vamshi] Method setName() is listed in the documentation but not
implemented in the source.

> [jh] I don't know where you see it listed but it was intentionally
removed. It shouldn't exist in current docs.

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?

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:

if (kid.getParent() != null) {
  kid.getParent().removeContent(kid);
}
if (kid.getDocument() != null) {
  // see later discussion
}
newParent.addContent(kid);

to simply:
	newParent.addContent(kid.detach())

(+1 for the old way:
  old root name > new root name  vs.  old parent > detach children > make
new parent > add detached children )

Even if the DocType were present, that could be changed easily to reflect
the change and keep the doc well-formed.

Try this:
   1. Element root = new Element("ROOT");
   2. DocType dt = new DocType(root.getName());
   3. Document d = new Document(root, dt);
   4. root.addContent(new Element("CHILD"));
   5. root.addChild(new Element("CHILD"));
	
Output: 
	<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE ROOT><ROOT><CHILD
/><CHILD /></ROOT>

at an arbitrary point in processing down the line, add: 
   6. root = new Element("NEWROOT");
   7. d.setRootElement(new Element("NEWROOT"));

Output:
	<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE ROOT><NEWROOT />

The children are missing. Also you need make sure to edit the DocType:

   8. dt = new DocType(root.getName());
   9. d.setDocType(dt);

Output:
	<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE NEWROOT><NEWROOT />

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 (?).

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.

I changed the code at that time but had to undo it. Any other easier way
out?

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.

What do the powers that be think?

- vamshi

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of
jdom-interest-request at jdom.org
Sent: Wednesday, December 27, 2000 11:12 PM
To: jdom-interest at jdom.org
Subject: jdom-interest digest, Vol 1 #404 - 4 msgs


Send jdom-interest mailing list submissions to
	jdom-interest at jdom.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://lists.denveronline.net/mailman/listinfo/jdom-interest
or, via email, send a message with subject or body 'help' to
	jdom-interest-request at jdom.org

You can reach the person managing the list at
	jdom-interest-admin at jdom.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of jdom-interest digest..."


Today's Topics:

   1. shema supported (Jian, David)
   2. Re: Any expected release date for 1.0? (Jason Hunter)
   3. Re: Suggestion (Jason Hunter)
   4. elt.detach() (Jason Hunter)

--__--__--

Message: 1
From: "Jian, David" <DJian at priceinteractive.com>
To: "'jdom-interest at jdom.org'" <jdom-interest at jdom.org>
Date: Wed, 27 Dec 2000 10:39:54 -0500
Subject: [jdom-interest] shema supported

What's the version of w3 schena JDOM supported? Does B5 support 10/24/2000
CR?

--__--__--

Message: 2
Date: Fri, 22 Dec 2000 11:44:07 -0800
From: Jason Hunter <jhunter at collab.net>
To: Michael Brennan <Michael_Brennan at Allegis.com>
CC: "'jdom-interest at jdom.org'" <jdom-interest at jdom.org>
Subject: Re: [jdom-interest] Any expected release date for 1.0?

It's an independent JSR.  JAXP is likely to support JDOM once the JSR
process has completed.  The JDOM JSR is not listed because it's just
getting started.

-jh-

Michael Brennan wrote:
> 
> Thanks for the info. Is there an independent JSR for it or is it being
> subsumed into JAXP? I wasn't able to find any reference to a JSR for this
on
> the Java Community Process web site.
> 
> Thanks.
> 
> > -----Original Message-----
> > From: Jason Hunter [mailto:jhunter at collab.net]
> > Sent: Thursday, December 21, 2000 11:49 PM
> > To: Michael Brennan
> > Cc: 'jdom-interest at jdom.org'
> > Subject: Re: [jdom-interest] Any expected release date for 1.0?
> >
> >
> > The API is getting pretty stable, but we're putting it through the JSR
> > process, and that comes with mandatory review periods with formal
> > community drafts, public drafts, and final drafts.
> >
> > -jh-

--__--__--

Message: 3
Date: Fri, 22 Dec 2000 20:13:46 -0800
From: Jason Hunter <jhunter at collab.net>
To: Mike Jennings <mjenning at islandnet.com>
CC: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Suggestion

> Mike Jennings wrote:
> 
> Hi,
> 
> What about adding a method to org.jdom.Element
> 
> public String getAttributeValue(String name, Namespace ns, String default)

There'd actually be two methods to add:

public String getAttributeValue(String name, String default)
public String getAttributeValue(String name, Namespace ns, String
default)

> Such that if the attribute named "name" does not exist, the String
> "default" is returned.
> This could be useful in cases where an XML file has default values for
> attributes
> that are not specified.
> 
> What do the powers that be think of this idea?

Seems to fit in nicely.  What do others think?

-jh-

--__--__--

Message: 4
Date: Wed, 27 Dec 2000 22:38:48 -0800
From: Jason Hunter <jhunter at collab.net>
To: JDOM Interest <jdom-interest at jdom.org>
Subject: [jdom-interest] elt.detach()

Hi,

I believe it would be useful to have an element.detach() method that
removes an  element from its parent (if there is a parent), and returns
the detached element afterward.  This simplifies the act of moving an
element to a new location from this right now:

if (kid.getParent() != null) {
  kid.getParent().removeContent(kid);
}
if (kid.getDocument() != null) {
  // see later discussion
}
newParent.addContent(kid);

to simply:

newParent.addContent(kid.detach())


The only tricky thing is what to do if the Element being "detached" is a
root element, as shown above.  Technically just removing a root elt from
its document makes the document no longer well-formed.  So perhaps we
could do something like oldDoc.setRootElement(new
Element("placeholder"))?

Ideas?

-jh-


--__--__--

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com

End of jdom-interest Digest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20001228/869ea03b/attachment.htm


More information about the jdom-interest mailing list