Using a StreamSource wrapped around an InputStream, the StreamSource doesn't
know where the file is. It could not even be a file, for all it knows, or it
could be from some weird protocol that doesn't have relative paths.
You should use the StreamSource(File) constructor, instead of creating your
own FileInputStream. That way the StreamSource has access to the File's
name, and it can resolve the relative paths.
Another option is to implement your own URIResolver to resolve the path
yourself. But the first option is a lot easier.
File file = new
File(boProps.XSL_DEFAULT_PATH+"\\panels\\"+name+".xml");
ByteArrayOutputStream out=new ByteArrayOutputStream();
transformer.transform(new StreamSource(file), new StreamResult(out));
result=new String(out.toByteArray());
Also, using ByteArrayOutputStream and converting the byte array into a String
will likely lose the document's character encoding information. If you have
any foreign or non-ASCII characters, this could mess it up and you will just
get weird symbols in your output. You should use a StringWriter instead:
StringWriter out=new StringWriter();
transformer.transform(new StreamSource(file), new StreamResult(out));
result = out.toString();
On the other hand, this will make the output not honor the stylesheet's
<xsl:output encoding="XXX"/>, but it will bypass the severe ugliness of the
String(byte[]) constructor. You should only write to an [Byte]OutputStream
if you are saving directly to a file and will read it back in with a
[Byte]InputStream.
On Wednesday 13 March 2002 12:32, Evgeniy Strokin wrote:
> Hi,
>
> question is:
>
> I have XML file with DTD:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!DOCTYPE panels SYSTEM "panel.dtd">
>
> <panels>
>
> <panel>
>
> <winHeader/>
>
> <winButton src="img/paste.gif" width="22"
> height="22" onclick="alert('test1')"/>
>
> <winButton src="img/tb_syncsch.gif" width="22"
> height="22"/>
>
> <winDropdown src="img/tb_syncsch.gif" width="22"
> height="22"/>
>
> <winSeparetor/>
>
> <winButton src="img/paste.gif" width="22"
> height="22"/>
>
> <winButtonTitle src="img/paste.gif" width="22"
> height="22" title="Titul Test"/>
>
> </panel>
>
> </panels>
>
> I�m trying do transformation in java object:
>
> TransformerFactory tFactory = TransformerFactory.newInstance();
>
> Transformer transformer = tFactory.newTransformer(new
> StreamSource(boProps.XSL_PANEL));
>
> InputStream is=new
> FileInputStream(boProps.XSL_DEFAULT_PATH+"\\panels\\"+name+".xml");
>
> ByteArrayOutputStream out=new ByteArrayOutputStream();
>
> transformer.transform(new StreamSource(is), new StreamResult(out));
>
> result=new String(out.toByteArray());
>
> I got this exception:
>
> org.xml.sax.SAXParseException: Relative URI "panel.dtd"; can not be
> resolved without a document URI.
>
> at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3030)
>
> at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3024)
>
> at
> org.apache.crimson.parser.Parser2.parseSystemId(Parser2.java:2622)
>
> at
> org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2600)
>
> at
> org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1111)
>
> at
> org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:488)
>
> at org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
>
> at
> org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
>
> at
> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java
>:573)
>
> at
> org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java
>:1071)
>
> DTD and XML file in same directory.
>
> What is problem?
>
>
>
> Thanks
>
>
>
> ---------------------------------
> Do You Yahoo!?
> Try FREE Yahoo! Mail - the world's greatest free email!
--
Peter Davis
finlandia:~> apropos win
win: nothing appropriate.