开发者

What would cause javax.xml.transform.Transformer.transform() to return empty string

I have a piece of code like this. I found that myResults = writer.getBuffer().toString(); returns an EMPTY STRING for some of the use cases but not for the other use cases.

I looked on the server but did not see any special characters in the x开发者_JS百科ml files. What would cause transformer.transform() to go wrong so the myResults = writer.getBuffer().toString(); returns an empty string? It does not return null, just an empty string.

    StringWriter writer = new StringWriter();
    Result result = new StreamResult(writer);
    try{
        transformer.transform(new StreamSource(theInputStream), result);
    }catch (Exception e) {
        e.printStackTrace();
    }

    myResults = writer.getBuffer().toString();

Thanks a lot,


I ran into this recently, but I'm not sure if its the same scenario.

I was developing on windows and deploying onto a linux box. Everything would transform fine on my windows machine, but on the linux box there where files which would transform, and files which would produce an empty file. I finally found the answer was in the line endings on the Xslt transforms. After changing the line endings to Linux style line endings the transforms worked fine.

Hope this helps.


I observed this behavior when my input XML was invalid. Not its schema, but syntactically incorrect. It contained <!-- -- -->. -- is not valid inside an XML comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜