A case of jumping in with both feet!  Apologies for implying that this 
may have been a bug (I've done you an injustice James :-) - of course, 
the 'elementIterator()' method is only intended to return elements ;-) 
...however, I do need an operation that returns all elements plus any 
text content for my particular application, so I'll use my solution.

Cheers,
Iain

FROM: Iain Potter
DATE: 01/09/2002 03:35:40
SUBJECT:  [dom4j-user] bug?

 

Hi,

I experienced what I think is a bug in the framework.  When a
DefaultText is added to a new DefaultElement and then the
elementIterator() method is called, the returned Iterator is empty.  Is
this behaviour expected or is it a bug?  I have written some sample code
(below) to illustrate what I mean.


QName name = new QName("Element");
DefaultElement element = new DefaultElement(name);

DefaultText text = new DefaultText("Text");
element.add(text);

// This does not return the text...
Iterator it = element.elementIterator();

while(it.hasNext())
{
      System.out.println("Child: " + it.next());
}

// ...this does
System.out.println(element.getText());


I can make the Iterator return the DefaultText by modifying the
elementIterator() method in the DefaultElement class.  The type-checking
of the content variable is modified to check for 'Node' instead of
'Element'.  I can simply use my modified code, but I would prefer to
have an 'official' build if this is a bug!

TIA,

Iain


-- 

Iain Potter
Senior Software Engineer
PrismTech Limited

www.prismtechnologies.com



_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to