我有一个1GB的Xml文件,如何使用Java将其拆分为格式正确的小型Xml文件?
这是一个例子:
<records>
<record id="001">
<name>john</name>
</record>
....
</records>
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个XML对象,当我将其转换为字符串时
public static String XMLElementToString(Document doc, Element e) {
// --- Output XML ---
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
StringWriter buffer = new StringWriter();
Result result = new StreamResult(buffer);
Source source = null;
if (e != null) {
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
source = new DOMSource(e);
} else {
source = new DOMSource(doc);
}
transformer.transform(source, result); // <-- Error occurs here
buffer.flush();
return buffer.toString();
} catch (TransformerException ex) {
System.out.println("exception: " + ex.getMessage()); …Run Code Online (Sandbox Code Playgroud) 如果我的问题无效,我很抱歉,但想知道 fastxml(jackson-dataformat-xml) 和 Woodstox 之间的关系是什么。文档(https://github.com/FasterXML/jackson-dataformat-xml)建议我在使用 jackson-dataformat-xml 时添加 Woodstox 的 Maven 依赖项。