jdom, adding child at specific location?

C

chiry

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
 
S

Sudsy

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?

I use Element.insertBefore( Node newChild, Node refChild );
 
K

Keith A. Lewis

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top