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

📄 e514. converting cdata nodes into text nodes while parsing an xml file.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
By default, CDATA nodes in an XML file will be represented with CDATASection objects in a DOM document. This example demonstrates how to create a parser that converts CDATA nodes into text nodes. 
    try {
        // Create a builder factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    
        // Configure it to coalesce CDATA nodes
        factory.setCoalescing(true);
    
        // Create the builder and parse the file
        Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));
    
        // doc will not contain any CDATA nodes
    } catch (SAXException e) {
        // A parsing error occurred; the xml input is not valid
    } catch (ParserConfigurationException e) {
    } catch (IOException e) {
    }

Here's some sample input: 
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
        Some pretext
        <![CDATA[Some text with lots of <"!@#$%'^&*()> special characters]]>
        Some posttext
    </root>

and output: 
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
        Some pretext
        Some text with lots of &lt;"!@#$%'^&amp;*()&gt; special characters
        Some posttext
    </root>


⌨️ 快捷键说明

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