<html>
<head>
</head>
<body>
You are correct, of course! I couldn't see it until you pointed out that
it must be there!<br>
<br>
Thanks!<br>
<br>
Geoff Rimmer wrote:<br>
<blockquote type="cite" cite="mid:m3wurnvgl3.fsf@dave.local">
<pre wrap="">David Kavanagh <a class="moz-txt-link-rfc2396E" href="mailto:dak@dotech.com"><dak@dotech.com></a> writes:<br></pre>
<blockquote type="cite">
<pre wrap=""><Document><br><String>this is a line of text<br/>and another line of text</String><br></Document><br><br>I call getContent() on the <String> element. I would expect to get a<br>List containing (Text, Element, Text) objects.<br></pre>
</blockquote>
<pre wrap=""><!----><br>Correct.<br><br></pre>
<blockquote type="cite">
<pre wrap="">[...] Then, I call getText() on the last Text object. I would expect<br>to get "and another line of text", but I don't. I get "this is a<br>line of textand another line of text".<br></pre>
</blockquote>
<pre wrap=""><!----><br>Sounds like a bug in your code.<br><br>The following code:<br><br> import java.io.StringReader;<br> import java.util.Iterator;<br> import java.util.List;<br> <br> import org.jdom.Element;<br> import org.jdom.Text;<br> import org.jdom.input.SAXBuilder;<br> <br> public class TextXml<br> {<br> public static void main( String[] args )<br> {<br> String s = "<Document><String>this is a line of text"<br> + "<br/>and another line of text</String></Document>";<br> <br> try<br> {<br> List list = new SAXBuilder().build( new StringReader( s ) )<br> .getRootElement().getChild( "String" ).getContent();<br> <br> for ( Iterator iter = list.iterator(); iter.hasNext(); )<br> {<br> Object obj = iter.next();<br> if ( obj instan
ceof Text )<br> {<br> Text text = (Text)obj;<br> System.out.println( "Text: " + text.getText() );<br> }<br> else if ( obj instanceof Element )<br> {<br> Element element = (Element)obj;<br> System.out.println( "Element: " + element.getName() );<br> }<br> else <br> {<br> System.out.println( "Something else" );<br> }<br> }<br> }<br> catch ( Exception cause )<br> {<br> System.err.println( "Exception: " + cause );<br> }<br> }<br> }<br> <br>outputs the following:<br><br> Text: this is a line of text<br> Element: br<br> Text: and another line of text<br><br>as expected, so it doesn't look like there's a problem with JDOM.<br><
br></pre>
</blockquote>
<br>
</body>
</html>