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

📄 e522. transforming an xml file with xsl into a dom document.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
// This method applies the xslFilename to inFilename and
    // returns DOM document containing the result.
    public static Document parseXmlFile(String inFilename, String xslFilename) {
        try {
            // Create transformer factory
            TransformerFactory factory = TransformerFactory.newInstance();
    
            // Use the factory to create a template containing the xsl file
            Templates template = factory.newTemplates(new StreamSource(
                new FileInputStream(xslFilename)));
    
            // Use the template to create a transformer
            Transformer xformer = template.newTransformer();
    
            // Prepare the input file
            Source source = new StreamSource(new FileInputStream(inFilename));
    
            // Create a new document to hold the results
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.newDocument();
            Result result = new DOMResult(doc);
    
            // Apply the xsl file to the source file and create the DOM tree
            xformer.transform(source, result);
            return doc;
        } catch (ParserConfigurationException e) {
            // An error occurred while creating an empty DOM document
        } catch (FileNotFoundException e) {
        } catch (TransformerConfigurationException e) {
            // An error occurred in the XSL file
        } catch (TransformerException e) {
            // An error occurred while applying the XSL file
        }
        return null;
    }

 Related Ex 

⌨️ 快捷键说明

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