我们正在将应用程序升级到 java6,并且与 java 5 一起使用的 xsl 转换现在返回一个空文档

发布于 2024-11-29 14:09:51 字数 408 浏览 0 评论 0原文

以前有人见过这样的事情吗?如果有必要的话,我会发布 xsl 和 xml,但我必须从中取出敏感数据。

用于处理 XSL 转换的代码:

TransformerFactory tFactory = TransformerFactory.newInstance(); 
Transformer transformer = tFactory.newTransformer(new DOMSource( xslDoc)); 
DOMResult domresult = new DOMResult(); 
transformer.transform(new DOMSource(xmlDoc), domresult); 
Node node = domresult.getNode(); 
resultDoc = (Document) node;

Has anybody seen anything like this before? I will post the xsl and xml if I have to but I would have to take sensitive data out of it.

The code used to handle the XSL transformation:

TransformerFactory tFactory = TransformerFactory.newInstance(); 
Transformer transformer = tFactory.newTransformer(new DOMSource( xslDoc)); 
DOMResult domresult = new DOMResult(); 
transformer.transform(new DOMSource(xmlDoc), domresult); 
Node node = domresult.getNode(); 
resultDoc = (Document) node;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2024-12-06 14:09:51

从来没见过它变成空白的。对于 JAVA6(也兼容 1.5),我有以下正在运行的代码,区别似乎在于使用的 TransformerFactory 上。

private DocumentBuilderFactory factory;
private DocumentBuilder builder;
private Transformer xformer;

//presetup - needs to be done just once
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
builder = factory.newDocumentBuilder();
xformer = TransformerFactory.newInstance().newTransformer();

//Transform the file
Source source = new DOMSource(doc);
String oFileName = "output.xml";
File oFile = new File(outputDirectory + "/" + oFileName); 
Result result = new StreamResult(oFile);
xformer.transform(source, result); 

这能解决您的问题吗?

Never seen it going blank. For JAVA6 (also compatible with 1.5), I have the following code that is working, the difference seems to on TransformerFactory used.

private DocumentBuilderFactory factory;
private DocumentBuilder builder;
private Transformer xformer;

//presetup - needs to be done just once
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
builder = factory.newDocumentBuilder();
xformer = TransformerFactory.newInstance().newTransformer();

//Transform the file
Source source = new DOMSource(doc);
String oFileName = "output.xml";
File oFile = new File(outputDirectory + "/" + oFileName); 
Result result = new StreamResult(oFile);
xformer.transform(source, result); 

Does this correct your issue?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文