??????????????????????????????????XML Load??????????????????????????????????Satx?????????????????????????????????????????XML?????Σ?
<OutXMLData>
<SubXMLItemType>
....
</SubXMLItemType>
<SubXMLItemType>
....
</SubXMLItemType>
<SubXMLItemType>
....
</SubXMLItemType>
....
</OutXMLData>
private static void readWriteWithStAXAndJAXB() throws FactoryConfigurationError?? FileNotFoundException?? XMLStreamException?? UnsupportedEncodingException?? JAXBException??
PropertyException {
// set up a StAX reader
XMLInputFactory xmlif = XMLInputFactory.newInstance();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("inputLarge.xml"));
XMLStreamReader xmlr = xmlif.createXMLStreamReader(bis);
File outfile = new File("output\outfile.xml");
OutputStreamWriter bos = new OutputStreamWriter(new FileOutputStream(outfile)?? "UTF-8");
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xmlw = xmlof.createXMLStreamWriter(bos);
xmlw.writeStartDocument("UTF-8"?? "1.0");
xmlw.writeStartElement("OutXMLData");
JAXBContext ucontext = JAXBContext.newInstance(SubXMLItemType.class);
Unmarshaller unmarshaller = ucontext.createUnmarshaller();
Marshaller marshaller = ucontext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT?? Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT?? Boolean.TRUE);
xmlr.nextTag();
xmlr.require(XMLStreamConstants.START_ELEMENT?? null?? "OutXMLData");
xmlr.nextTag();
int iCount = 0;
while (xmlr.getEventType() == XMLStreamConstants.START_ELEMENT) { // ???????????
iCount++;
JAXBElement<SubXMLItemType> pt = unmarshaller.unmarshal(xmlr?? SubXMLItemType.class); // ???????SubItem??????
marshaller.marshal(pt?? xmlw); // ??????????д??
xmlw.writeCharacters(" ");
if (xmlr.getEventType() == XMLStreamConstants.CHARACTERS) {
xmlr.next();
}
}
xmlw.flush();
xmlw.writeEndElement();
xmlw.writeEndDocument();
System.out.println("Entity Count is :" + iCount);
xmlr.close();
xmlw.close();
}
????????????????????Java????XML?????????????????????????????У?????з?????????????????????????磬????XML????????????????????????????????γ????????????????????????????磬????Stax????XML???????DOM?????????????????????????????ù????????????????е??????????????????????????????????XML???????Sub??XML???????XML??Σ?????з??XML?????????????????????Java??Object??????????????????С??XML??????????????????????????????????????????????????????
????Java ??XML???????и?transform?????????????????о????????????????????????????????????????Stax ?? Sax ????Dom ?????任??????任??Stream??