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();
}
}
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();
}
}