I won't say if the error you pointed is a bug.. But following is a
modified code which seems to work.
public static void main(String[] args) throws Exception {
SAXTransformerFactory tf = (SAXTransformerFactory)
SAXTransformerFactory.newInstance();
TransformerHandler writer = tf.newTransformerHandler();
StreamResult streamResult = new StreamResult(new File("myout.xml"));
writer.setResult(streamResult);
writer.startDocument();
AttributesImpl empty = new AttributesImpl();
AttributesImpl att = new AttributesImpl();
att.addAttribute("", "font-family", "fo:font-family", "CDATA", "Tahoma");
writer.startPrefixMapping("office", "http://openoffice.org/2000/text");
writer.startPrefixMapping("fo", "http://openoffice.org/2000/style");
writer.startElement("", "document", "office:document", empty);
writer.startElement("", "word", "office:word", att);
writer.endElement("", "word", "office:word");
writer.endElement("", "document", "office:document");
writer.endDocument();
}
It produces output -
<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:office="http://openoffice.org/2000/text"
xmlns:fo="http://openoffice.org/2000/style">
<office:word fo:font-family="Tahoma"/>
</office:document>
Regards,
Mukul
On 5/10/05, Chris Bitmead (JIRA) <[email protected]> wrote:
> [
> http://issues.apache.org/jira/browse/XALANJ-2118?page=comments#action_64804 ]
>
> Chris Bitmead commented on XALANJ-2118:
> ---------------------------------------
>
> Below is an example program and the resulting output. As you can see, the
> namespace URI is specified for the "fo" namespace and yet it doesn't come out
> in the output.
>
> package untitled2;
> import java.io.File;
> import javax.xml.transform.sax.SAXTransformerFactory;
> import javax.xml.transform.sax.TransformerHandler;
> import javax.xml.transform.stream.StreamResult;
> import org.xml.sax.helpers.*;
>
> public class Untitled1 {
> public static void main(String[] args) throws Exception {
> SAXTransformerFactory tf = (SAXTransformerFactory)
> SAXTransformerFactory.newInstance();
> TransformerHandler writer = tf.newTransformerHandler();
> StreamResult streamResult = new StreamResult(new
> File("c:/tmp/myout.x"));
> writer.setResult(streamResult);
> writer.startDocument();
> AttributesImpl empty = new AttributesImpl();
> AttributesImpl att = new AttributesImpl();
> att.addAttribute("http://openoffice.org/2000/style", "font-family",
> "fo:font-family", "CDATA", "Tahoma");
> writer.startElement("http://openoffice.org/2000/text", "document",
> "office:document", empty);
> writer.startElement("http://openoffice.org/2000/text", "word",
> "office:word", att);
> writer.endElement("http://openoffice.org/2000/text", "word",
> "office:word");
> writer.endElement("http://openoffice.org/2000/text", "document",
> "office:document");
> writer.endDocument();
> }
> }
>
> <?xml version="1.0" encoding="UTF-8"?>
> <office:document xmlns:office="http://openoffice.org/2000/text">
> <office:word fo:font-family="Tahoma"/>
> </office:document>
>
> > 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]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]