[jdom-interest] Bug in SAXBuilder for mixed content

Michael Hinchey michael.hinchey at inference.com
Fri Jun 9 20:00:25 PDT 2000


Of the four documents (below), I think the first two have correct output,
but 3 and 4 do not.  I would gues the problem is in SAXBuilder, which counts
me out for offering a quick fix, as I know nothing about SAX.  Calling
getChild("c") on the elements throws a NoSuchElementException for documents
3 and 4.  (I'm using the June5 source.)

The following code...

public class JDOMTest {
  public static void main(String[] args) throws Exception {
    checkMixedContent("<nomix><c>c1</c><c>c2</c></nomix>");
    checkMixedContent("<mix><c>c1</c><!-- comment --></mix>");
    checkMixedContent("<mix><c>c1</c>m2</mix>");
    checkMixedContent("<mix>m1<c>c1</c>m2</mix>");
  }

  public static void checkMixedContent(String xml) throws Exception {
    System.out.println(xml);
    org.jdom.Document document = new org.jdom.input.SAXBuilder().build(
      new java.io.StringReader(xml) );
    org.jdom.Element element = document.getRootElement();
    System.out.println("\thasMixedContent:\t" + element.hasMixedContent());
    System.out.println("\tgetContent:   \t\t" + element.getContent());
    System.out.println("\tgetChildren:  \t\t" + element.getChildren());
    //System.out.println("\tgetChild(c):  \t\t" + element.getChild("c"));
    System.out.println("\tgetMixedContent:\t" + element.getMixedContent());
  }
}

Produces ...

<nomix><c>c1</c><c>c2</c></nomix>
	hasMixedContent:	false
	getContent:   		
	getChildren:  		[[Element: <c />], [Element: <c />]]
	getMixedContent:	[[Element: <c />], [Element: <c />]]
<mix><c>c1</c><!-- comment --></mix>
	hasMixedContent:	true
	getContent:   		
	getChildren:  		[[Element: <c />]]
	getMixedContent:	[[Element: <c />], [Comment: <!--  comment
-->]]
<mix><c>c1</c>m2</mix>
	hasMixedContent:	false
	getContent:   		m2
	getChildren:  		[]
	getMixedContent:	[m2]
<mix>m1<c>c1</c>m2</mix>
	hasMixedContent:	false
	getContent:   		m1m2
	getChildren:  		[]
	getMixedContent:	[m1m2]



Received: from server1.software-ag.de (server1.software-ag.de [193.26.194.2])
	by dorothy.denveronline.net (8.9.3/8.9.3) with SMTP id GAA12965
	for <jdom-interest at jdom.org>; Fri, 9 Jun 2000 06:44:13 -0600 (MDT)
Message-ID: <0BED5B805890D31184D90000F6CD6B481AAA85 at chmsg01.software-ag.de>
From: "Arvidsson, Hokan" <hokan.arvidsson at softwareag.com>
To: "'jdom-interest at jdom.org'" <jdom-interest at jdom.org>
Date: Fri, 9 Jun 2000 14:46:10 +0200 
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01BFD210.B025F310"
Subject: [jdom-interest] A second XMLPutter.output() signature.
Sender: jdom-interest-admin at jdom.org
Errors-To: jdom-interest-admin at jdom.org
X-BeenThere: jdom-interest at jdom.org
X-Mailman-Version: 2.0beta2
Precedence: bulk
List-Id: JDOM Mailing List for General Issues and Updates <jdom-interest.jdom.org>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01BFD210.B025F310
Content-Type: text/plain;
	charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,
=20
After generating a jdom Document from some stream you'd might like to =
write
the result into another stream.
In the result file, all =FC characters were converted into =C2=BC.
I could only get this working by removing the encoding in
XMLPutter.output().
=20
I'm now using these parameter signatures:
=20
public void output(Document doc, OutputStream out) throws IOException; =
// No
encoding
public void output(Document doc, OutputStream out, String enc) throws
IOException;

=20
It would be nice seeing this feature in the upcoming release (unless =
the
problem may be solved in another way).
=20
Cheers,
H=E5kan
=20
=20
H=E5kan Arvidsson
Consultant
Software AG Switzerland
Tel. ..41-1-745 91 11
=20

------_=_NextPart_001_01BFD210.B025F310
Content-Type: text/html;
	charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DISO-8859-1">


<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000>Hi=20
all,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000>After =
generating a=20
jdom Document from some stream you'd might like to&nbsp;write the =
result into=20
another stream.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000>In =
the result file,=20
all =FC characters were converted into =C2=BC.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000>I =
could only get=20
this working by removing the encoding in =
XMLPutter.output().</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000>I'm =
now using these=20
parameter signatures:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D434373112-09062000>public void=20
output(Document doc, OutputStream out) throws IOException; // No=20
encoding<BR><FONT face=3DArial size=3D2><SPAN =
class=3D434373112-09062000>public void=20
output(Document doc, OutputStream out, String enc) throws=20
IOException;<BR></SPAN></FONT></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000><FONT =
face=3DArial=20
size=3D2><SPAN =
class=3D434373112-09062000>&nbsp;</DIV></SPAN></FONT></SPAN></FONT>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D434373112-09062000>It =
would be nice=20
seeing this feature in the upcoming release (unless the problem may be =
solved in=20
another way).</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000>Cheers,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000>H=E5kan</DIV></SPAN></FONT>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D434373112-09062000></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D434373112-09062000></SPAN></FONT><FONT=20
face=3DArial size=3D2>H=E5kan Arvidsson</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Consultant</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Software AG Switzerland</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Tel. ..41-1-745 91 11</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01BFD210.B025F310--



More information about the jdom-interest mailing list