[jdom-interest] XMLOutputter changes from b8 to b9

Rolf Lear rlear at algorithmics.com
Fri Jan 16 11:50:35 PST 2004


What about the

<element xml:space="preserve">
  

  This element should never have it's whit-sepace altered

   OK?

</element>


Example? If space is important in an XML document, then it is important
emough to declare the space to be preserved.

See http://www.w3.org/TR/REC-xml#sec-white-space

Rolf Lear

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Per Norrman
Sent: Friday, January 16, 2004 2:45 PM
To: 'Beleznay, Dave'; 'Bradley S. Huffman'
Cc: jdom-interest at jdom.org
Subject: SV: [jdom-interest] XMLOutputter changes from b8 to b9


Hi,

Instead of 
        xmlOutputter.setTextTrim(true);
try
        xmlOutputter.setTrimAllWhite(true);

At least your test case says yay!

/pmn

PS. Is it imprudent to ask why those spaces would ever be significant?
Philosophically speaking, what you want is to treat whitespace
differently depending
on the context in which it appears: What if the three spaces in <type>
</type> 
is as significant as those in <type>   Migration</type>. If that's the
case, 
you loose. DS.


> -----Ursprungligt meddelande-----
> Från: jdom-interest-admin at jdom.org 
> [mailto:jdom-interest-admin at jdom.org] För Beleznay, Dave
> Skickat: den 16 januari 2004 19:46
> Till: Bradley S. Huffman
> Kopia: jdom-interest at jdom.org
> Ämne: RE: [jdom-interest] XMLOutputter changes from b8 to b9 
> 
> 
> Really?  that is odd,  it might be my copy of the jar file, I 
> wasn't the one who downloaded it, I'll try getting a new copy 
> and trying again. Are you sure that the spaces in the element 
> <type> were preserved?
> 
> I've attatched my test class here, can you try running it 
> when you get a chance?
> 
> Thank you.
> 
> Cheers,
> 
> Dave
> 
> > -----Original Message-----
> > From: Bradley S. Huffman [mailto:hip at cs.okstate.edu]
> > Sent: Thursday, January 15, 2004 6:49 PM
> > To: Beleznay, Dave
> > Cc: jdom-interest at jdom.org
> > Subject: Re: [jdom-interest] XMLOutputter changes from b8 to b9 
> > 
> > 
> > When I uncomment the following line in your code I get the
> > results you want with B9.
> > 
> >          //xmlOutputter.setTextTrim(true);
> > 
> > Brad
> > 
> > "Beleznay, Dave" writes:
> > 
> > > Hi There,
> > > 
> > > We've recently upgraded from Jdom b8 to b9, and had a few 
> errors in
> > > the upgrade process.
> > > 
> > > If I have an XML document like so:
> > > 
> > >         String xml =3D=20
> > >             "<enterprise>\n"+
> > >             "<properties>\n"+
> > >             "    <datasource>WebCT</datasource>\n"+
> > >             "    <type>  Migration</type>\n"+
> > >             "    <datetime>2002-06-06T14:59:05</datetime>\n"+
> > >             "</properties>\n"+
> > >             "</enterprise>\n";
> > > 
> > > Where the spaces in front of <datasource> are not 
> relevant, but the
> > > spaces inside the elements (e.g. <type>) are relevant (this 
> > is just a
> > > fragment of a larger bit of XML, it isn't really the <type>
> > field that
> > > matters here). When I put the document into Jdom, I get different
> > > behaviour between Jdom b8 and b9.  I'd like to know the expected 
> > > behaviour, and if it doesn't match my desired behaviour, 
> > approximately
> > > how I'm supposed to fix my code. =20
> > > 
> > > 
> > > Using the string above and the following code in Jdom b8  
> I get the
> > > output below.
> > > 
> > >         SAXBuilder builder =3D new SAXBuilder();
> > >         Document doc =3D builder.build(new StringReader(xml));
> > >        =20
> > >         XMLOutputter xmlOutputter =3D new 
> XMLOutputter("\t", true);
> > >         xmlOutputter.setOmitDeclaration(true);
> > >         xmlOutputter.setLineSeparator("\n");
> > >         //xmlOutputter.setTextTrim(true);
> > >         String output =3D =
> > > xmlOutputter.outputString(doc.getRootElement());
> > >         System.out.println(output);
> > > 
> > > Desired output ( and output received from b8):
> > > 
> > > output=3D
> > > 
> > 
> "<enterprise>\n\t<properties>\n\t\t<datasource>WebCT</datasource>\n\t\
> > > t<
> > > type>
> > > 
> > 
> Migration</type>\n\t\t<datetime>2002-06-06T14:59:05</datetime>\n\t</pr
> > > op
> > > erties>\n</enterprise>"
> > > 
> > > 
> > > When we upgraded to Jdom b9 we were in for a little bit of a
> > > surprise.=20
> > > 
> > > Output from b9 without TextTrim:
> > > 
> > > output=3D "<enterprise>\n\t\n\n\t<properties>\n\t\t\n
> > > \n\t\t<datasource>WebCT</datasource>\n\t\t\n    \n\t\t<type>
> > > Migration</type>\n\t\t\n
> > > 
> > 
> \n\t\t<datetime>2002-06-06T14:59:05</datetime>\n\t\t\n\n\t</properties
> > > >\
> > > n\t\n\n</enterprise>"
> > > 
> > > Output from b9 with TextTrim:
> > > 
> > > output=3D
> > > 
> > 
> "<enterprise>\n\t<properties>\n\t\t<datasource>WebCT</datasource>\n\t\
> > > t<
> > > 
> > 
> type>Migration</type>\n\t\t<datetime>2002-06-06T14:59:05</datetime>\n\
> > > type>t<
> > > /properties>\n</enterprise>"
> > > 
> > > (this is close, but took the spaces out before "   Migration" )=20
> > > 
> > > Unfortunately the code farther down the line (not using
> > jdom) which is
> > > analyzing the xml has problems with the string  "\n\t\t\n
> > > \n\t\t<datasource>WebCT<datasource>" and interprets the 
> value as " 
> > > WebCT". I'm not happy with that either, but right now it's 
> > easier to
> > > fix the behaviour of Jdom.
> > > 
> > > It looks like this was changed XMLOutputter 1.87, and I'm 
> trying to
> > > figure out why.  I'd like to remove the whitespace outside the 
> > > elements, while preserving the whitespace inside.  As a temporary 
> > > measure I've added the check for currentFormat.newlines 
> back to our 
> > > skipLeadingWhite method in XMLOutputter, but I'd like a 
> > more permanent
> > > solution. =20
> > > 
> 

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list