[
http://issues.apache.org/jira/browse/XALANJ-2118?page=comments#action_64957 ]
Chris Bitmead commented on XALANJ-2118:
---------------------------------------
Two points:
Firstly, can anyone give a rational answer why it would automatically insert
namespace declarations for tags but not attributes? I mean, if this is so bad
with performance hits etc, why does it happen for tags? If it is so bad, you
should turn it off for tags too, because otherwise people get the impression
their code is working, and then it suddenly stops working for this unusual
case. Be consistent.
Secondly, if startPrefixMapping events MUST be reported, then it seems to me
that the XMLReader should report them when it finds a declaration in the XML.
If the XMLReader reported them then I could pass these events straight through
the stream and everything would be sweet.
Surely for consistencies sake, if you are going to insist that users give SAX
the prefix mapping, then you should give the same courtesy to the user and
report the prefix mapping in the input.
This would not only allow a SAX stream to pass through from XMLReader through
filters to an XMLWriter intact and still valid, but it has the added benefit
that the namespaces will still be declared EXACTLY where they were declared on
the input, which is also an efficiency for certain structures of XML.
Below is some test code to show that this doesn't happen.
package untitled3;
import java.io.*;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.helpers.*;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.*;
public class Untitled1 {
public static void main(String[] args) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter wr = new OutputStreamWriter(baos);
wr.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
wr.write("<office:document
xmlns:office=\"http://openoffice.org/2000/text\">");
wr.write("<office:word fo:font-family=\"Tahoma\"/>");
wr.write("</office:document>");
wr.close();
XMLReader reader =
SAXParserFactory.newInstance().newSAXParser().getXMLReader();
ByteArrayInputStream bais = new
ByteArrayInputStream(baos.toByteArray());
InputStreamReader ir = new InputStreamReader(bais);
InputSource source = new InputSource(ir);
XMLFilterImpl ch = new XMLFilterImpl() {
public void startPrefixMapping(String prefix, String uri) throws
SAXException {
System.out.println("THIS WONT HAPPEN - PREFIX: " + prefix + " -
" + uri);
}
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws
SAXException {
System.out.println("start: " + namespaceURI + " - " + qName);
}
};
reader.setContentHandler(ch);
reader.parse(source);
}
}
> No namespace declarations for attributes
> ----------------------------------------
>
> Key: XALANJ-2118
> URL: http://issues.apache.org/jira/browse/XALANJ-2118
> Project: XalanJ2
> Type: Bug
> Components: SAX
> Versions: 2.6
> Environment: Win XP
> Reporter: Chris Bitmead
> Priority: Critical
>
> I'm using Xalan SAX to write OpenOffice.org documents, and these documents
> sometimes use a namespace "fo" as in "fo:font-family", but it only uses this
> namespace for attributes, not for tags and Xalan doesn't create the
> appropriate namespace declaration for these attributes when writing the
> document out with SAX. I have tried this with the xalan built into Java 1.5.0
> as well as tried the 2.6.0 xalan.jar dropped into the lib/endorsed directory
> in Java 1.4.2, but both exhibit this behaviour.
> This seems like a bug to me, is it?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]