[jdom-interest] Reinitialisation
Gareth Hughes
gareth.hughes at steintravel.ie
Fri Aug 20 09:20:58 PDT 2004
Thanks for the help....
Couldn't get it to work at first but amended to the following and its
working fine now.
List content = element.getParent().getContent();
for(int i=0;i<content.size();i++){
Object o = content.get(i);
if(o instanceof Element){
Element el = (Element)o;
if(el == element){ // element - Element to be removed
int index = content.indexOf(el);
content.remove(index);
if (index > 0
&& content.get(index - 1) instanceof Text
&& ((Text) content.get(index -
1)).getTextTrim().length() == 0) {
content.remove(index - 1);
}
}
}
}
Any thoughts or comments appreciated.
Cheers..
-----Original Message-----
From: Per Norrman [mailto:per.norrman at austers.se]
Sent: 20 August 2004 15:40
To: Gareth Hughes
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] Reinitialisation
Gareth Hughes wrote:
> I'm building a JDOM Doc and eventually attaching the resulting XML doc to
a
> SAAJ SOAPMessage. I'm using the SOAPMessage.writeTo method to output the
> message to a file for visual verification. The attached XML contains a
blank
> line where I removed the element in question (using
> Parent.removeContent(element)).
>
> This is causing problems with my SOAP req. I hoping there is some way I
can
> reinitialise the JDOM doc before attachment to the SOAPMessage.
>
> Any help is much appreciated.
>
Help is on the way:
/*
* Remove an element and any immediatley preceding whitespace
*/
Element e = ....
List content = e.getParent().getContent();
int index = content.indexOf(e);
content.remove(index);
if (index > 0
&& content.get(index - 1) instanceof Text
&& ((Text) content.get(index - 1)).getTextTrim().length() == 0) {
content.remove(index - 1);
}
/pmn
More information about the jdom-interest
mailing list