⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e523. generating sax parsing events by traversing a dom document.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
If you have developed a set of handlers for SAX events, it is possible to use these handlers on a source other than a file. This example demonstrates how to use the handlers on a DOM document. 
    // Obtain a DOM document; this method is implemented in
    // e510 The Quintessential Program to Create a DOM Document from an XML File
    Document doc = parseXmlFile("infilename.xml", false);
    
    // Prepare the DOM source
    Source source = new DOMSource(doc);
    
    // Set the systemId of the source. This call is not strictly necessary
    URI uri = new File("infilename.xml").toURI();
    source.setSystemId(uri.toString());
    
    // Create a handler to handle the SAX events
    DefaultHandler handler = new MyHandler();
    
    try {
        // Prepare the result
        SAXResult result = new SAXResult(handler);
    
        // Create a transformer
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
    
        // Traverse the DOM tree
        xformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
    }
    
    // DefaultHandler contain no-op implementations for all SAX events.
    // This class should override methods to capture the events of interest.
    class MyHandler extends DefaultHandler {
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -