[jdom-interest] API enhancement request: Element.removeConten
PMcFarlane at lendx.com
Tue Feb 26 14:00:05 PST 2002
Yes, I am using beta7. I very much look forward to beta8. Thanks for the
By the way, thanks for writing such a clean API. It's definitely one of my
favorite Java API to work with. You've made creating and navigating XML
documents easy! :)
From: Jason Hunter [mailto:jhunter at acm.org]
Sent: Tuesday, February 26, 2002 1:51 PM
To: Patrick McFarlane
Cc: 'jdom-interest at jdom.org'
Subject: Re: [jdom-interest] API enhancement request:
You're using beta7 I presume. The code in CVS is much, much better, and
includes code that better manages parent relationships.
Yes, we'll be doing a beta8 soon. :-)
Patrick McFarlane wrote:
> Again maybe I'm missing something, but when I use the setContent(null)
> method or getContent().clear() my content still has parent relationships
> that I get an error messages like the following:
> org.jdom.IllegalAddException: The comment " Display Element Definitions "
> could not be added as content to "localizableDisplay": The comment already
> has an existing parent "localizableDisplay"
> If I use the Element removeChildren() method, that sets the parent
> relationship to null which lets me avoid the problem above. I'm wondering
> a removeContent method could also free the parent relationships of what
> I'm sure that I can work around this by iterating through my list of
> and doing the equivalent of a detach() for each, but I just thought this
> might be a useful method to add.
> -----Original Message-----
> From: Jason Hunter [mailto:jhunter at acm.org]
> Sent: Monday, February 25, 2002 6:54 PM
> To: Patrick McFarlane
> Cc: 'jdom-interest at jdom.org'
> Subject: Re: [jdom-interest] API enhancement request:
> Well, with the present API you can setContent(null) or
> getContent().clear(). Do we need another method beyond that?
> In your usage would it not suffice to say
> parentElem.setContent(updatedList) and skip the removeContent() step?
> Patrick McFarlane wrote:
> > Not sure if this is in the works or intentionally left out or if
> > I've missed something, but, it seems that Element removeContent(), which
> > removes all of the various types of content (CDATA, Comment, Element,
> > from an element without passing an Object argument would be very useful.
> > This would be roughly analogous to the Element removeChildren(). The
> > Element setContent(List) is available and it seems odd that Element
> > removeContent() is not. My usage is replacing an existing bit of content
> > with a revised copy of the content via Jaxen/XPath, keeping the order
> > intact. I would like to do the following:
> > Element oldElem = findElementUsingXPath(elementPath);
> > Element parentElem = oldElem.getParent();
> > List siblings = parentElem.getContent();
> > // find the location of the element to update
> > int location = findEqualElement(siblings, oldElem);
> > // create a new List with the new element added Before
> > addBefore element
> > List updatedList =
> > replaceElementInList(siblings,location,newElem);
> > // remove existing chilren
> > parentElem.removeContent(); // This method does not
> > currently exist
> > // add new list of children to parent
> > parentElem.setContent(updatedList);
> > Thanks in advance,
> > patrick
> > _______________________________________________
> > To control your jdom-interest membership:
More information about the jdom-interest