473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

HTMLSerializer with xalan

I'm trying to generate HTML using a SAX TransformHandler. The problem
I'm having is related to the xalan transformer using the shorthand
notation when it writes out an empty textarea tag. My code works fine
when xalan.jar is not in my classpath. But when xalan.jar is in the
classpath, the generated html incorrectly uses the shorthand notation
for writing out an empty textarea tag.

Correct output:

C:\test>java Test
com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerImpl
<html>
<body>
<textarea></textarea>GoodBye</body>
</html>

Incorrect output:

C:\test>java -classpath .;/tomcat5/common/lib/xalan.jar Test
org.apache.xalan.transformer.TransformerIdentityIm pl
<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<textarea/>GoodBye</body>
</html>
As you can see from the above example, when xalan is involved, the
generated output results in HTML that confuses IE. Is there a way to
force xalan into NOT using the short hand notation for the textarea
tag?

Here's the source code of my program:

public static void main( String [] args )
{
try {
// prepare the output transform handler
SAXTransformerFactory tf =
(SAXTransformerFactory) TransformerFactory.newInstance();
TransformerHandler transformerHandler =
tf.newTransformerHandler();

Transformer serializer = transformerHandler.getTransformer();
System.out.println( serializer.getClass().getName() );
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
transformerHandler.setResult( new StreamResult( System.out ) );

transformerHandler.startDocument();
Attributes noAtts = new AttributesImpl();

transformerHandler.startElement("", "", "html", noAtts );
transformerHandler.startElement("", "", "body", noAtts );

transformerHandler.startElement(
"", "", "textarea", noAtts );
transformerHandler.endElement("", "", "textarea" );
String msg = "GoodBye" ;
transformerHandler.characters( msg.toCharArray(),
0, msg.length() );

transformerHandler.endElement("", "", "body" );

transformerHandler.endElement("", "", "html" );
transformerHandler.endDocument();
}
catch ( Exception e ) {
e.printStackTrace();
}
}

Jul 20 '05 #1
5 1746
I'm still looking for an answer to this one. My opinion on the matter
is that <textarea/> should be considered perfectly legal xhtml.
However, IE 6.0, isn't smart enough to handle it. That's why I was
looking for a possible work around that doesn't involve forcing a space
between the start and end of the element.

Jul 20 '05 #2
John wrote:
I'm still looking for an answer to this one. My opinion on the matter
is that <textarea/> should be considered perfectly legal xhtml.
However, IE 6.0, isn't smart enough to handle it. That's why I was
looking for a possible work around that doesn't involve forcing a space
between the start and end of the element.


Exactly, both <textarea></textarea> and <textarea/> are equivalent
and valid xhtml.

Couldn't you just leave out the textarea at all?

Gerald
Jul 20 '05 #3
John wrote:
I'm still looking for an answer to this one. My opinion on the matter
is that <textarea/> should be considered perfectly legal xhtml.
However, IE 6.0, isn't smart enough to handle it. That's why I was
looking for a possible work around that doesn't involve forcing a space
between the start and end of the element.


another idea: let your xhtml validate by the w3c validator.

if it is not valid xhtml then the browser will switch to
quirks-mode (see FAQ at http://www.quirksmode.org/)

HTH
Gerald
Jul 20 '05 #4
John wrote:
I'm still looking for an answer to this one. My opinion on the matter
is that <textarea/> should be considered perfectly legal xhtml.
1. The subject contains HTMLSerializer. The serializer for _HTML_ should
not create <textarea/>.

2. According to the XML spec you should only use the empty element
notation for elements that are empty by definition, which textarea is not.
However, IE 6.0, isn't smart enough to handle it.


IE 6.0 does not know XHTML.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jul 20 '05 #5
John wrote:
I'm still looking for an answer to this one. My opinion on the matter
is that <textarea/> should be considered perfectly legal xhtml.
It's legal as XML, but violates the notorious Appendix C of XHTML.
So it's not legal to serve on the Web as "text/html".
However, IE 6.0, isn't smart enough to handle it.
Indeed. But if you serve it as text/html then XML rules don't apply,
so IE is within its rights not treating <foo/> as <foo></foo>.

That's why I was looking for a possible work around that doesn't involve forcing a space
between the start and end of the element.


http://apache.webthing.com/mod_xhtml/

--
Nick Kew
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: al dav | last post by:
Hi all ok i am not a java programmer I am a sys-admin, my users want xalan and have already got j2sdk_1.4.2 so i have downloaded it and set the CLASS_PATH export...
0
by: Guillaume Jeudy | last post by:
Hi, I'm trying to serialize a DOM constructed from the following URL which is subject to change very frequently: ...
1
by: Fisch von Gestern | last post by:
I have tried to run the extension function/element examples provided with the Xalan-J download. I believe that my classpath is correct, and that my versions are up-to-date. However, I can't get...
7
by: Ganesh Gella | last post by:
Hi All, I am planning to use Xalan to transform XML data by applying xls stylesheets. Here tricky part is, Xalan provides several C++ APIs, which are very much useful if our requirement is...
2
by: Dr. Roger Wießner | last post by:
Hello! I am a newbie to XSLT and need a freeware/GNU Tool to get experience with this new topic. Which one is a good XSLT? Xalan or Saxon, or which one else? Thank you a lot!
7
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet...
0
by: terry.jeske | last post by:
Hello, I am trying to upgrade an application that was previously running on Xalan 1.4.2, to 2.7.0. I have worked out the build issues and now the application compiles with the new xalan and...
3
by: Avalon1178 | last post by:
Hi, I recently downloaded the xalan-c source code in http://mirrors.ccs.neu.edu/Apache/dist/xml/xalan-c I followed the instructions from the apache site on how to build it (I already have...
2
by: henribastien | last post by:
I'm trying to return an array from a xalan extension but so far I have made no progress. What I would like to return is something like that <entry id="red">201</entry> <entry...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.