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

📄 e516. preventing expansion of entity references while parsing an xml file.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
By default, entity references are expanded during parsing. This example demonstrates how to leave the entity references in the DOM document 
Note: The default parser in J2SE 1.4 expands entity references in attribute values. There is no way to prevent this. 

    // Parses an XML file without expanding entity references and returns
    // a DOM document. If validating is true, the contents is validated
    // against the DTD specified in the file.
    public static Document parseXmlFileNoExpandER(String filename, boolean validating) {
        try {
            // Create a builder factory
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(validating);
    
            // Prevent expansion of entity references
            factory.setExpandEntityReferences(false);
    
            // Create the builder and parse the file
            Document doc = factory.newDocumentBuilder().parse(new File(filename));
            return doc;
        } catch (SAXException e) {
            // A parsing error occurred; the xml input is not valid
        } catch (ParserConfigurationException e) {
        } catch (IOException e) {
        }
        return null;
    }

⌨️ 快捷键说明

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