Java Mailing List Archive

http://www.junlu.com/

Google Search
Google


Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
XMLOutputter changes from b8 to b9

XMLOutputter changes from b8 to b9

2004-01-15       - By Beleznay, Dave

 Back
Reply:     1     2     3     4     5     6     7     8     9  

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 =
           "<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.


Using the string above and the following code in Jdom b8  I get the
output below.

       SAXBuilder builder = new SAXBuilder();
       Document doc = builder.build(new StringReader(xml));

       XMLOutputter xmlOutputter = new XMLOutputter("\t", true);
       xmlOutputter.setOmitDeclaration(true);
       xmlOutputter.setLineSeparator("\n");
       //xmlOutputter.setTextTrim(true);
       String output = xmlOutputter.outputString(doc.getRootElement());
       System.out.println(output);

Desired output ( and output received from b8):

output"<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</prop
erties>\n</enterprise>"


When we upgraded to Jdom b9 we were in for a little bit of a surprise.

Output from b9 without TextTrim:

output= "<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"<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<
/properties>\n</enterprise>"

(this is close, but took the spaces out before "   Migration" )

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.

Thank you very much.

Cheers,

Dav

--
David Beleznay
Software Engineer
WebCT
__ ____ ____ ____ ____ ____ ____ ____ ____ ____
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)
.com



Earn $52 per hosting referral at Lunarpages.
©2008 junlu.com - Jax Systems, LLC, U.S.A.