编写 xml 错误
public static void writeXmlFile(Document doc, String filename) {
try {
// Prepare the DOM document for writing
Source source = new DOMSource(doc);
// Prepare the output file
File file = new File(filename);
Result result = new StreamResult(file);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance()
.newTransformer();
xformer.transform(source, result);
} catch (TransformerConfigurationException e) {
} catch (TransformerException e) {
}
}
我正在使用此函数将 xml 写入文件,一切正常,但在最后一个结束标记之前添加了一行,如下所示。
[Mar 13 15:40:16] INFO (ConnectionController.java:342) -
我从来没有使用过这个类,为什么这个日期是 3 月 13 日,即使我不知道
这是一个常见问题吗?
public static void writeXmlFile(Document doc, String filename) {
try {
// Prepare the DOM document for writing
Source source = new DOMSource(doc);
// Prepare the output file
File file = new File(filename);
Result result = new StreamResult(file);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance()
.newTransformer();
xformer.transform(source, result);
} catch (TransformerConfigurationException e) {
} catch (TransformerException e) {
}
}
i am using this function to write xml into a file, everything comes fine but one line is being added as follows just before last ending tag.
[Mar 13 15:40:16] INFO (ConnectionController.java:342) -
i am neer using this class and why is this mar 13 date even i dont know
is it a common issue ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们可以排除该文档已经包含该文本吗?因为这将是一个非常简单的解决方案:错误不会在打印期间发生,但可能在文档生成期间发生。
要进行调查,您可以迭代 root 的子节点(而不是元素)并检查末尾附近是否有可疑的文本或 cdata 节点。
至少它看起来像一条日志消息,是在机器系统日期设置为 2010 年 3 月 13 日时生成的。
Can we exclude that the document contains the text already? Because that would be a pretty easy solution: the error wouldn't occur durcing printing but maybe during document generation.
To investigate, you could just iterate over the child nodes of root (not elements) and check whether there is a suspicious text or cdata node near the end.
At least it looks like a log message, generated when the machine system date was set to March, 13 2010.
显然还有其他东西正在写入同一个文件。对我来说看起来像一个记录器。
我希望这不是你真正的异常处理。
Clearly something else is writing to the same file. Looks like a logger to me.
I hope that isn't your real exception handling.