[From nobody Wed Mar 16 15:30:34 2005 Return-Path: <jdom-interest-bounces@jdom.org> Delivered-To: el@grit.de Received: from localhost (localhost [127.0.0.1]) by mail.grit.de (Postfix) with ESMTP id 2A79C2FE77 for <el@grit.de>; Thu, 17 Mar 2005 00:30:12 +0100 (CET) Received: from servlets.kattare.com (servlets.com [65.212.180.182]) by mail.grit.de (Postfix) with ESMTP id AFBA1129E0 for <el@grit.de>; Thu, 17 Mar 2005 00:30:10 +0100 (CET) Received: from servlets.kattare.com (localhost [127.0.0.1]) by servlets.kattare.com (8.12.10/8.12.11) with ESMTP id j2GNC2Ke001522; Wed, 16 Mar 2005 15:12:04 -0800 Received: from csmtp.b-one.net (csmtp.b-one.net [195.47.247.21]) by servlets.kattare.com (8.12.10/8.12.11) with ESMTP id j2GNBsCI023254 for <jdom-interest@jdom.org>; Wed, 16 Mar 2005 15:12:00 -0800 Received: from [10.0.1.129] (unknown [84.217.11.189]) by csmtp.b-one.net (Postfix) with ESMTP id 7236DFB981; Thu, 17 Mar 2005 00:11:50 +0100 (CET) Message-ID: <4238BD33.7030300@austers.se> Date: Thu, 17 Mar 2005 00:11:47 +0100 From: Per Norrman <per.norrman@austers.se> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: sv, en-us, en MIME-Version: 1.0 To: markup@osmosislatina.com Subject: Re: [jdom-interest] Test - Expanding <script> element. References: <4237ACB3.8090707@osmosislatina.com> <42387BEF.4030902@xquery.com> <423899AA.20609@osmosislatina.com> In-Reply-To: <423899AA.20609@osmosislatina.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: hip@a.cs.okstate.edu, jdom-interest@jdom.org, Jason Hunter <jhunter@xquery.com> X-BeenThere: jdom-interest@jdom.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: JDOM Mailing List for General Issues and Updates <jdom-interest.jdom.org> List-Unsubscribe: <http://www.jdom.org/mailman/listinfo/jdom-interest>, <mailto:jdom-interest-request@jdom.org?subject=unsubscribe> List-Archive: <http://www.jdom.org/pipermail/jdom-interest> List-Post: <mailto:jdom-interest@jdom.org> List-Help: <mailto:jdom-interest-request@jdom.org?subject=help> List-Subscribe: <http://www.jdom.org/mailman/listinfo/jdom-interest>, <mailto:jdom-interest-request@jdom.org?subject=subscribe> Sender: jdom-interest-bounces@jdom.org Errors-To: jdom-interest-bounces@jdom.org X-Virus-Scanned: by AMaViS 0.3.12pre8 Hi, I *think* I know what's happening: 1) The DTD used declares xml:space="preserve" for the script element. This attribute is #FIXED, which means that JDOM cannot tell if it was in the source or not, the XML parsers reports it nevertheless. 2) You use prettyFormat and tell it to expand empty elements. When this line is parsed <script src="jscript/mylibrary.js" type="text/javascript"></script> the JDOM tree will look like this: X Element name=script Attribute name=src value=jscript/mylibrary.js Attribute type=text/javascript Attribute xml:space=preserve N.B. no content! The printElement method in XMLOutputter will look for the xml:space attribute and switch to another format if the attribute is present and its value is preserve, for the purpose of prserving space. However, the expandEmptyElement property of this format is false, which means that elements with xml:space="preserve" and no content will always be unexpanded. Conclusion: Probably, the temporary preserveFormat should reflect the expandEmptyElement property of the userFormat. Daniel Rubio skrev: > > Just replicated the "would-be" bug, here is what I found out from making > the test: > .- This behavior happens only if the > input/document has a defined Doctype, in this case XHTML Strict or > Transitional > .- If there is no Doctype in the input/document the > behavior is as expected, not even the xml:space="preserve" attribute is > added to the output. > > What baffles me now is what JAR/Library in the stack takes this > Doctype input and produces an altered final output (The not expanding > the particular script tag appropriately and adding the > xml:space="preserve" attribute) . > > Any ideas (Xerces , Jaxen or something else in JDOM ) ? > Daniel > Attaching Test.java and and testData.html > > > > > > > ------------------------------------------------------------------------ > > > import org.jdom.*; > import org.jdom.output.*; > import org.jdom.input.*; > import java.io.*; > > public class Test { > > public static void main(String[] args) { > try { > > SAXBuilder builder = new SAXBuilder(); > Document doc = builder.build("testData.html"); > Format documentFormat = Format.getPrettyFormat(); > documentFormat.setExpandEmptyElements(true); > > // Adding the doctype at this point is still irrelevant > // DocType dtd = new DocType("html","-//W3C//DTD XHTML 1.0 Strict//EN","http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); > // doc.setDocType(dtd); > > XMLOutputter outputter = new XMLOutputter(documentFormat); > outputter.output(doc, System.out); > } catch (JDOMException jdom) { > jdom.printStackTrace(); > } catch (IOException io) { > io.printStackTrace(); > } > > } > } > > > ------------------------------------------------------------------------ > > > ------------------------------------------------------------------------ > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com ]