Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2003

Tip: Looking for answers? Try searching our database.

jdom, adding child at specific location?

Thread view: 
chiry@csua.berkeley.edu - 13 Sep 2003 00:36 GMT
Is there a way to make Element.addContent add the content at a
specific location?

I need to update an existing jdom object in memory, by adding/removing
some elements. problem is, addContent() always add at the end, and as
a result the resulting XML object doesn't validate against the XSD
file.

Is there a way to add an element at a specific location?

Thanks.

Raymond
Sudsy - 13 Sep 2003 13:21 GMT
> Is there a way to make Element.addContent add the content at a
> specific location?
[quoted text clipped - 5 lines]
>
> Is there a way to add an element at a specific location?

I use Element.insertBefore( Node newChild, Node refChild );
Keith A. Lewis - 16 Sep 2003 21:19 GMT
chiry@csua.berkeley.edu writes in article <bjtl91$1rtr$1@agate.berkeley.edu> dated Fri, 12 Sep 2003 23:36:01 +0000 (UTC):

>Is there a way to make Element.addContent add the content at a
>specific location?

No, not AFAIK.

>I need to update an existing jdom object in memory, by adding/removing
>some elements. problem is, addContent() always add at the end, and as
>a result the resulting XML object doesn't validate against the XSD
>file.
>
>Is there a way to add an element at a specific location?

Yes.  You can use Element.getContent() to get the content as a List, then use
List.add(int, Object) to insert the new content wherever you see fit.  

Caution -- You can add any object to the content this way, only some of
which are valid in JDOM.

--Keith Lewis              klewis$mitre.org
The above may not (yet) represent the opinions of my employer.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.