[jdom-interest] Element.setContent

jimfah at coolmail.net jimfah at coolmail.net
Wed Oct 4 14:30:28 PDT 2000


Thanks Alex,

I had looked at getMixedContent() but was too lazy to iterate thru it.  
Now that I have I get the desired result but ugly......

  java.util.List kids = ele.getMixedContent();
  java.util.ListIterator li = kids.listIterator();
  int cnt = 0;
  while (li.hasNext()) {
     if (li.next().getClass().getName().equalsIgnoreCase("java.lang.String")) {

          kids.set(cnt,(Object) sContent);
      }
      cnt += 1;
   }

Is ther a better way of getting to the content?!  Looking for the class "java.lang.String" is some major cheese.

Thanks,
Jim

-----Original Message-----
From:     Alex Chaffee <guru at edamame.stinky.com>
Sent:     Wed, 4 Oct 2000 12:28:26 -0700
To:       jimfah at coolmail.net
Cc:       jdom-interest at jdom.org
Subject:  Re: [jdom-interest] Element.setContent

> Element.setContent(String) clears the linked list.  Is that the
> desired result?  All the children of that element are gone when I
> change the content.  If it should clear the list then shouldn't
> there be a Element.getContent() that returns a List instead of a
> string.  And a Element.setContent(List)?

Look at Element.getMixedContent()

public java.util.List getMixedContent()

	This returns the full content of the element as a List which may
	contain objects of type String, Element, Comment,
	ProcessingInstruction, and Entity. When there is technically no mixed
	content and all contents are of the same type, then all objects
	returned in the List will be of the same type. The List returned is
	"live" and modifications to it affect the element's actual
	contents. Whitespace content is returned in its entirety.


(Yes, if it had been called getContentMixed or getContentFull, it
would show up in the alphabetical Javadoc next to getContent(), but
that's no excuse for not reading the whole API, Jim :-))

 - A

-- 
Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/



____________________________________________
CoolMail(tm).  Hear.  There.  Everywhere.(sm)
E-mail by phone - http://www.planetarymotion.com



More information about the jdom-interest mailing list