HTMLSerializer with xalan

J

John

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.TransformerImpl
<html>
<body>
<textarea></textarea>GoodBye</body>
</html>

Incorrect output:

C:\test>java -classpath .;/tomcat5/common/lib/xalan.jar Test
org.apache.xalan.transformer.TransformerIdentityImpl
<?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();
}
}
 
J

John

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.
 
G

Gerald Aichholzer

John said:
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
 
G

Gerald Aichholzer

John said:
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
 
J

Johannes Koch

John said:
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.
 
N

Nick Kew

John said:
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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top