Convert DOM to SAX
Chuyển đổi từ DOM sang SAX.
Nhớ lưu ý phải tham chiếu đến thư viện xerces.jar. Download tại http://apache.org/.
import org.apache.xerces.parsers.DOMParser; import org.apache.xml.serialize.XMLSerializer; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class DOM2SAX{ public static void main(String[] args){ String xmlFile=“xmlfiles/books.xml” ; try{ InputSource Isource = new InputSource(xmlFile); DOMParser Dparser = new DOMParser(); Dparser.parse(Isource); //convert 2 SAX Document doc = Dparser.getDocument(); //process XMLSerializer serializer = new XMLSerializer(); serializer.setOutputByteStream(System.out); serializer.serialize(doc); } catch (Exception e){ e.printStackTrace(); } } } |