您可以使用StAX(
javax.xml.stream)解析器并将
javax.xml.transform每个部分转换()到DOM节点(
org.w3c.dom):
import java.io.*;import javax.xml.stream.*;import javax.xml.transform.*;import javax.xml.transform.stax.StAXSource;import javax.xml.transform.dom.DOMResult;import org.w3c.dom.*public class Demo { public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to statements element TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { DOMResult result = new DOMResult(); t.transform(new StAXSource(xsr), result); Node domNode = result.getNode(); } }}
另请参阅:
- 使用Java分割1GB Xml文件
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)