You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2001/11/30 17:57:18 UTC
DO NOT REPLY [Bug 5210] New: -
INCREMENTAL, Xerces-2.0.0b3 and root element namespace declaration causes error
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5210>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5210
INCREMENTAL, Xerces-2.0.0b3 and root element namespace declaration causes error
Summary: INCREMENTAL, Xerces-2.0.0b3 and root element namespace
declaration causes error
Product: XalanJ2
Version: 2.2.x
Platform: PC
OS/Version: Windows NT/2K
Status: NEW
Severity: Normal
Priority: Other
Component: org.apache.xalan.processor
AssignedTo: xalan-dev@xml.apache.org
ReportedBy: george.hawkins@pobox.com
CC: george.hawkins@pobox.com
Using Xalan-Java 2.2.D13 and Xerces-Java 2.0.0 Beta 3 create a
TransformerFactory and set the FEATURE_INCREMENTAL attribute to true:
> TransformerFactory factory = TransformerFactory.newInstance();
>
> factory.setAttribute(TransformerFactoryImpl.FEATURE_INCREMENTAL,
> Boolean.TRUE);
If you now attempt to transform an XML document that declares a
namespace in the root element then the following error is reported:
> The root element is required in a well-formed document.
This does error does not occur in any the following situations:
1. You use the version of Xerces (apparently 1.4.3) that ships with Xalan.
2. You don't set the FEATURE_INCREMENTAL attribute to true.
3. The root element of the XML document does not declare a namespace.
(Declaring a namespace in any element other than the root always works
without problem.)
Below I've included a Java file 'Process.java' along with a trivial XSL
stylesheet 'test.xsl' and an XML document 'test.xml' that declares a
namespace in the the root element to demonstrates this problem.
The following shows how to compile and run this program. I've renamed
the Xerces JAR file that came with Xalan to 'xalan-xerces.jar' and the
one that comes with Xerces 2.0.0 Beta 3 to 'xerces-2.0.0b3.jar'.
------------------------------------------------------------------------
javac -classpath xalan.jar:xml-apis.jar Process.java
> java \
-classpath .:xalan.jar:xml-apis.jar:xalan-xerces.jar \
Process test.xsl test.xml
No errors.
> java \
-classpath .:xalan.jar:xml-apis.jar:xerces-2.0.0b3.jar \
Process test.xsl test.xml
No errors.
> java \
-classpath .:xalan.jar:xml-apis.jar:xalan-xerces.jar \
Process -incremental test.xsl test.xml
No errors.
> java \
-classpath .:xalan.jar:xml-apis.jar:xerces-2.0.0b3.jar \
Process -incremental test.xsl test.xml
[Fatal Error] test.xml:6:2: The root element is required in a well-formed
document.
------------------------------------------------------------------------
File: Process.java
------------------------------------------------------------------------
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import org.apache.xml.utils.DefaultErrorHandler;
import org.apache.xalan.processor.TransformerFactoryImpl;
import java.io.PrintWriter;
public class Process
{
public Process(String xslFilename, String xmlFilename, boolean incremental)
{
try
{
StreamSource xslSource = new StreamSource(xslFilename);
StreamSource xmlSource = new StreamSource(xmlFilename);
TransformerFactory factory = TransformerFactory.newInstance();
Templates stylesheet = factory.newTemplates(xslSource);
StreamResult result = new StreamResult(System.out);
if (incremental)
{
factory.setAttribute(
TransformerFactoryImpl.FEATURE_INCREMENTAL, Boolean.TRUE);
}
Transformer transformer = stylesheet.newTransformer();
transformer.transform(xmlSource, result);
}
catch (Throwable throwable)
{
PrintWriter writer = new PrintWriter(System.err, true);
DefaultErrorHandler.printLocation(writer, throwable);
}
}
private static void usage()
{
System.err.println("Usage: Process [-incremental] stylesheet.xsl
file.xml");
System.exit(1);
}
public static void main(String args[])
{
boolean incremental = false;
int pos = 0;
if (args.length == 3)
{
if (!args[0].equals("-incremental")) usage();
pos++;
incremental = true;
}
else if (args.length != 2) usage();
new Process(args[pos], args[pos + 1], incremental);
}
}
------------------------------------------------------------------------
File: test.xml
------------------------------------------------------------------------
<?xml version="1.0"?>
<!--
<message>
-->
<message xmlns="x-schema:schema.xml">
</message>
------------------------------------------------------------------------
File: test.xsl
------------------------------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>